Koin Extended & Experimental Features
about external & incubation features
Better definition declaration (Experimental)
Koin DSL can be seen as “manual”, while you must fill constructors with “get()” function to resolve needed instances. When your definition don’t need any special constructor integration (injection paarameters or special scope Id), we can go with more compact writing style thanks to API below.
note: Using reflection is not costless. it replaces what you don”t want to write with reflection code (finding primary constructors, injecting parameters…). Mind it before using it, if you are on performances constraints platform (Android for example)
Instance builder with create()
The first introduced function is the
Instead of declaring a definition with instantiating its constructor and retrieving instances with get()
You can use instead, the
create() function to build an instance from its primary constructor, and fill the needed dependencies.
More simple definitions
You can also use the more “compact” notation that will use the
create() function. Just use the single function without any expression:
If you have an implementation type and want to resolve with a target type, you can use the following
Also works for factory & scope definition!
Below are some further readings: