I have a question concerning how the Unity container I have set up is resolving controller dependencies. I've been searching around for an explanation of this but haven't found anything that is real clear on the subject. And maybe the answer is staring me in the face... Take a look at the following code that I'm 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 that is my override of GetControllerInstance in my controller factory that I have set up. Obviously, the controller types are being resolved out of the Unity container but how are they getting registered in the container in the first place? How does the MVC framework know to register types in the container? I realize that the types are being resolved out of that container but I don't like not knowing how it is resolving the controller types.