Dependency injection(Autofac equivalent for resolvebyname or key)

294 Views Asked by At

It was very handy with Autofac on dependency injection.

Recently I changed project where lightinject and unitycontainer uses. Here I am able to register a list of services with a name, but I'm unable to resolve by a name.

I tried to get it as IEnumerable. I'm getting all, but not the name I registered. So I'm unable to distinguish them.

What am I missing here?

1

There are 1 best solutions below

1
On BEST ANSWER

https://www.tutorialsteacher.com/ioc/property-injection-using-unity-container see the section Named Mapping

 public class Service {
     [Dependency("AName")]
     public IDependency Dependency {get;set;}
 }