Inject generic type?
See original GitHub issueIs it possible to inject a generic type? I’m getting a cyclical error when I try to inject two generic types. For example:
if I had class Generic<T>
can I start koin like this?
bean { Generic<FirstClass>() }
bean { Generic<SecondClass>() }
I’m only getting cyclical errors, even when I include a dependency name. Any help would be appreciated.
org.koin.error.DependencyResolutionException: Cyclic dependency detected while resolving my.Generic - [Factory[name='first', class=my.Generic]]
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Why is it impossible to inject generic classes? - Stack Overflow
I have a generic abstract template class. I thought if I create type-specific Producers, I could inject some DAO service directly in the ......
Read more >Smart Dependency Injection With Spring - Generics - DZone
Here, we shed some light on the injection of beans defined by a generic class. For this topic, we need another set of...
Read more >ASP.NET Core Dependency Injection - Code with Steve
A short post exploring how generic types can be registered with the Microsoft Dependency Injection container provided with ASP.NET Core.
Read more >Crossing the Generics Divide - Jimmy Bogard
Remember, void Main is not generic, so at some point, your program needs to cross the generic divide. Sometimes, this is explicit (you ......
Read more >Advanced Scenarios — Simple Injector 5 documentation
Simple Injector can handle open-generic types, closed-generic types and partially-closed generic types. The sections below provides more detail on Simple ...
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 Free
Top 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
Solved by c02e72ed723704fe78a2e98046a178b4edbe6f68
Thanks!
@majkrzak Koin doens’t support generics the way you are probably thinking of. The fix only pertained to named dependencies.
Some solution are using qualified (named) dependencies or non-generic definitions.