question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inject generic type?

See original GitHub issue

Is 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:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
caleb-allencommented, Mar 10, 2018

Solved by c02e72ed723704fe78a2e98046a178b4edbe6f68

Thanks!

1reaction
erickokcommented, Mar 19, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found