tappeddev / injector

Simple dependency injection for Dart. 💉
Apache License 2.0
77 stars 7 forks source link

Named definitions #14

Closed AlexeyPoldeo closed 5 years ago

AlexeyPoldeo commented 5 years ago

It will be great to add optional name parameter on registering and getting an object

JulianBissekkou commented 5 years ago

so you are able to get the dependency with that name later on? What is your use case for this feature?

AlexeyPoldeo commented 5 years ago

Yes. Sometimes it's required to inject objects of same class, but different purposes. Like username and password - both are String.

stefanschaller commented 5 years ago

Okay, we will do it. But you need always the type info. So it will looks like this:


injector.registerDependency<UserService>(dependencyName: "UserService2", (injector) => UserServiceImpl())..

and you get your dependency like this:


injector.getDependency<UserService>(dependencyName: "UserService2");

Are you fine with that?

stefanschaller commented 5 years ago

In version 1.0.5 we added support for named dependencies

AlexeyPoldeo commented 5 years ago

But this is not reflected in Readme...