c# - Unity container, how to inject an specific class based on the "calling" class -


i have following snippet

 public static void registercomponents(iunitycontainer container)     {         // register components container here         // not necessary register controllers         container.registertype<isocialclient, clienta>("a");         container.registertype<isocialclient, clientb>("b");         container.registertype<isocialclient, clientc>("c");          globalconfiguration.configuration.dependencyresolver = new unitydependencyresolver(container);     } 

this webapi2 project. have 3 controllers,

public class socialacontroller : apicontroller {     private isocialclient client;     ... } 

is there way in unity configure, socialacontroller "clienta" implementation, socialbcontroller "clientb" implementation?

mspasiuk,

you can registering example socialacontroller way:

    container.registertype<socialacontroller>(new injectionconstructor(new resolvedparameter<isocialclient>("a"))); 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -