I have implemented dependency injection in MVC 3 unity framework and following the instructions.
It worked , but I have a few questions regarding this:
Here is my implementation :
public interface ID
{
string MReturn();
}
And the classes which implement this interface are:
public class D:ID
{
public string MReturn()
{
return "Hi";
}
}
public class E : ID
{
public string MReturn()
{
return "HiE";
}
}
public class F : ID
{
public string MReturn()
{
return "Hif";
}
}
In the bootstrapper class ,
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
container.RegisterType<ID, D>();
container.RegisterType<IController, HomeController>("feedbackRepo");
container.RegisterType<ID, E>();
container.RegisterType<ID, F>();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
return container;
}
Now my question is
"I want to set the service class D in the Homecontroller constructor, but according to the above code, it is setting "class F" in the constructor.
Is there any way to do this?any modification to the above code?