I'm using structure map in my asp mvc site, which i've just tried to deploy onto II6 for the first time.
The basic dependency structure is very typical:
public ControlMController(IControlMService controlMservice)
{
this._controlMservice = controlMservice;
}
...
public ControlMService(IControlMRepository repo)
{
this._repo = repo;
}
...
public SQLControlMRepository (CTRLMDataContext dataContext)
{
_db = dataContext;
}
My structureMap Registry is like this
For<IControlMService>().Use<ControlMService>();
For<IControlMRepository>().Use<SQLControlMRepository>();
//For<IControlMRepository>().Use<TestControlMRepository>();
SelectConstructor<CTRLMDataContext>(() => new CTRLMDataContext());
For<CTRLMDataContext>().LifecycleIs(new HybridLifecycle()).Use<CTRLMDataContext>();
My Controller Factory looks like this:
public class ControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
try
{
if (controllerType == null) return base.GetControllerInstance(requestContext,controllerType);
return ObjectFactory.GetInstance(controllerType) as IController;
}
catch
{
System.Diagnostics.Debug.WriteLine(ObjectFactory.WhatDoIHave());
return null;
}
}
}
This works 100% on the development server, but it does not work on when i deployed to IIS 6 on a server.
The ControlMController which has all of the dependenies returns the following exception:
[InvalidOperationException: The IControllerFactory 'SupportTool.web.Controllers.ControllerFactory' did not return a controller for the name 'ControlM'.]
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +304
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
All of the the other controllers which have 0 dependencies work fine on the server, so the installation of structuremap must be working a little, just not entirely :/