jonsamwell / flutter_simple_dependency_injection

A super simple dependency injection implementation for flutter that behaviours like any normal IOC container and does not rely on mirrors
MIT License
93 stars 8 forks source link

please add func static get Injection #2

Closed Alekcei closed 5 years ago

Alekcei commented 5 years ago

Please add static Inection.get(SometType)

jonsamwell commented 5 years ago

@Alekcei I am not sure what you mean? You can already do this

Injector.getInjector("injectorInstanceName").get<SomeType>();

or to get the default instance of the injector

Injector.getInjector().get<SomeType>();
Alekcei commented 5 years ago

I want get defult instance by short chain

Injector.get<SomeType>();
jonsamwell commented 5 years ago

@Alekcei I don't think this adds anything to the library and in a way would start to promote a bad practice. The injector "getInstance" method was implemented on purpose as you can have multiple instances of injectors. I think the default use case would be to only use your injector in a container during application startup to configure all the services. Thereafter, everything is injected so you shouldn't need to access the injector.

Nonetheless why not just do this?

final injector = Injector.getInjector();
injector.get<SomeType>()
Alekcei commented 5 years ago

i setting service in my widget, the following way.

  final httpService = Injector.getInjector().get<HttpService>();
  final carService  = Injector.getInjector().get<CarService>();

I wanted have short chain for this.

Alekcei commented 5 years ago

Whether it is possible to add a binding by annotations

  @Injection
  final HttpService httpService;
jonsamwell commented 5 years ago

Sorry @Injection notation would rely on mirrors which is not available in Flutter.