Posted by ercu
I could not find anything related to this anywhere, but if you know there is a simple but breaking change in asp.net mvc version 2.0.0.0's DefaultControllerFactory, so WindsorContainerFactory got broken.
Because it could not get the instance of controller from controller factory, I kept getting the following error everytime i loaded my fresh web project built with asp.net mvc v2.
No parameterless constructor defined for this object.
Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
While searching for a solution around the web, I found the following lines in the release notes of mvc version 2:
DefaultControllerFactory API changes will break custom controller factories that derive from it
This change affects custom controller factories that derive from DefaultControllerFactory . The DefaultControllerFactory class was fixed by removing the RequestContext property and instead passing the request context instance to the protected virtual methods GetControllerInstance and GetControllerType.
So I just fetched latest MvcContrib source, changed GetControllerInstance found in WindsorContainerFactory.cs to work with latest mvc library by taking RequestContext as parameter. I rewrote
the function as follows.
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if(controllerType == null)
{
throw new HttpException(404, string.Format("The controller for path '{0}' could not be found or it does not implement IController.", requestContext.HttpContext.Request.Path));
}
return (IController)_container.Resolve(controllerType);
}
[/code]
Then it worked as I expected. Hope this helps anyone.