Bind for generic types
See original GitHub issueI can’t find a solution to bind generic types and construct instances for them
val kodein by Kodein.lazy {
bind<Generic<*>>() with factory { cls:TypeToken<Generic<*>> ->
... create instance based on actual * type
}
Onse i trying to get instance with
val generic:Generic<String> by instance
got
com.github.salomonbrys.kodein.Kodein$NotFoundException: No provider found for bind<Generic<String>>() with ? { ? }
Registered in Kodein:
bind<Generic<*>>() with factory { TypeToken<Generic<*>> -> Generic<String> }
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10 (3 by maintainers)
Top Results From Across the Web
How do I bind a Generic class? - java - Stack Overflow
This is what I tried: bind(new TypeLiteral<AbstractDao<MyDomain>>(){}).to(ConcreteDao.
Read more >Allow binding generic functions to a given type #37181 - GitHub
So I suggest to provide a syntax that allows to do just that: fix type arguments of generic functions: type Box<T> = ReturnType<typeof...
Read more >How to: Examine and Instantiate Generic Types with Reflection
Information about generic types is obtained in the same way as ... Call the MakeGenericType method to bind the type arguments to the...
Read more >Binding generic types using a metatype parameter - Success!
Binding generic types using a metatype parameter about trying to dynamically bind a generic type's parameter to any other type. Well, I finally ......
Read more >[ninject] Binding open generic types to generic providers?
I sometimes need to bind open generics, which works fine using the syntax: ... What's odd is that if I make the provider...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Kodein 5 offers “subtype factories” and “external source” that both answer your needs.
I found a workaround. A little bit verbose, but dos not require to iterate all POJO in bind statement.
So first of all create a binder like
then create inline extension to KodeinInjected or any other Kodein aware interface
and finnaly retrive it with short expressive statement.