StructureMap and ASP.NET MVC 2 gave me a nice little error that you and others might run across. The solution is quick and easy - unless you don't know it (LOL). While moving one of my applications from MVC 1 to MVC 2, I came across the StructureMap error. Here is the offending StructureMap code I used in ASP.NET MVC 1.
CODE THAT DOES NOT WORK IN ASP.NET MVC 2It looks like it should work right? Well it did work, but guess what? Times have changed....well StructureMap has changed. So now the code should look like the following:
protected override IController GetControllerInstance(Type controllerType)
{
if (controllerType == null) return null;
try
{
return (IController)ObjectFactory.GetInstance(controllerType);
}
catch (StructureMapException)
{
System.Diagnostics.Debug.WriteLine(ObjectFactory.WhatDoIHave());
throw;
}
}
CODE THAT WILL WORK IN ASP.NET MVC 2And there you have it! Changes, changes, changes! I hope this puts a smile on your face or at least lets you get back to work.
protected override IController GetControllerInstance(RequestContext requestContext,
Type controllerType)
{
if (controllerType == null)
return base.GetControllerInstance(requestContext, controllerType);
try
{
return (IController)ObjectFactory.GetInstance(controllerType);
}
catch (StructureMapException)
{
System.Diagnostics.Debug.WriteLine(ObjectFactory.WhatDoIHave());
throw;
}
}
Smooches,
Kila
No comments:
Post a Comment