Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get all instances from DI as List<AbstractClass> #424

Open
slkmikhail opened this issue Jan 4, 2024 · 3 comments
Open

How to get all instances from DI as List<AbstractClass> #424

slkmikhail opened this issue Jan 4, 2024 · 3 comments

Comments

@slkmikhail
Copy link

HI!

Could you give advice how to get all instances from DI as List?

I have AbstractClass and more than one implementations (singleton).
I'd like to get all of them from DI as List without additional efforts.

@bahricanyesil
Copy link

Did you find any solution @slkmikhail?

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

@RLittlesII
Copy link

I used a similar approach to #470 (comment). Not sure if it's the "right" way but it works for my use case.

@module
abstract class ThingOperationModule {
  @lazySingleton
  List<Thing> get things =>
      GetIt.instance.getAll<Thing>().toList(growable: false);
}

...

abstract class Thing {}

@Named("thingone")
@Injectable(as: Thing)
final class ThingOne extends Thing {}

@Named("thingtwo")
@Injectable(as: Thing)
final class ThingTwo extends Thing {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants