Asp.net mvc is not using the controller factory specified

asp.net-mvc

I am using ASP.NET MVC Preview 2 that is installed with VS2010 Beta 2. I am hooking up WindsorControllerFactory like so:

Container = new WindsorContainer();
Container.RegisterControllers(typeof(HomeController).Assembly);
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container));

My HomeController has one dependency that is passed into the constructor, when running I am getting the following error:

No parameterless constructor defined for this object.

[MissingMethodException: No parameterless constructor defined for

this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType
type, Boolean publicOnly, Boolean
noCheck, Boolean& canBeCached,
RuntimeMethodHandle& ctor, Boolean&
bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean
publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean
publicOnly, Boolean
skipVisibilityChecks, Boolean
fillCache) +230
System.Activator.CreateInstance(Type
type, Boolean nonPublic) +67
System.Activator.CreateInstance(Type
type) +6
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext
requestContext, Type controllerType)
+522

[InvalidOperationException: An error occurred when trying to create a

controller of type
'Xenotar.WedPlannerPro.Controllers.HomeController'.
Make sure that the controller has a
parameterless public constructor.]
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext
requestContext, Type controllerType)
+659
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext
requestContext, String controllerName)
+198
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase
httpContext) +225
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext
httpContext) +86
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext
httpContext) +36
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+181
System.Web.HttpApplication.ExecuteStep(IExecutionStep
step, Boolean& completedSynchronously)
+75

By looking at this stack trace it does not look like MVC is using the WindsorControllerFactory but instead it still uses the DefaultControllerFactory?

When doing this in MVC 1.0 it works.

SOLUTION

The MvcContrib is not compatible with ASP.NET MVC 2.

Best Answer

You should be able to modify MvcContrib to work with ASP.NET MVC 2. The code for controller registration is pretty minimal.

Related Topic