I have a question about how the Unity container I installed is resolving controller dependencies. I searched for an explanation of this, but did not find anything that would be clearly visible on this issue. And maybe the answer looks me in the face ... Take a look at the following code, which I am sure many MVC guys have seen:
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
{
IController controller;
try
{
controller = container.Resolve(controllerType) as IController;
}
catch (Exception ex)
{
throw new InvalidOperationException(string.Format("Error resolving controller {0}", controllerType.Name), ex);
}
return controller;
}
So this is my redefinition GetControllerInstancein my factory controller that I configured. Obviously, controller types are allowed from a Unity container, but how are they registered in the container in the first place? As you know, the MVC structure registers types in a container? I understand that types are resolved from this container, but I don't like not to know how it resolves controller types.