Wednesday, 15 April 2015

dependency injection - Autofac DependencyResolver of same service with 2 different services -


I have a service with two separate components

  & lt; Component Type = "Concrete A, Concrete A" Service = "Interface, Interface" /> & Lt; Component Type = "Concrete, Concrete" service = "Interface, Interface" />  

I want to solve both of them. I am trying this way

  var builder = new containerbuilder (); the creator. Registration Manager (new configuration reader); Builder.RegisterControllers (typeof (MvcApplication) .asembly); this. _ Container = Builder. Build (); Dependance Resolver. SetsSolar (New AutoFacDirection Resolver (it._container));  

Now in my controller I want to solve my dependency

  public interface _myInterface {get; Set; }  

And I use it this way:

  _myInterface.DoWork ();  

If I declare only one component in the conference, then everything works perfectly. But if I add more component of the same interface type, then something goes wrong I

  public list & lt; Interface & gt; With the attempt to change the declaration of property. _myInterfaces {get; Set; }  

But the property always remains ... How can I do this?

Thanks

the solution

  public Interface [_] _myInterfaces {get; Set; }  

instead of

  public list & lt; Interface & gt; _myInterfaces {get; Set; }  

No comments:

Post a Comment