Search code examples
c#dependency-injectionunity-containerautofaclight-inject

Dependency injection(Autofac equivalent for resolvebyname or key)


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?


Solution

  • 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;}
     }