Paul Creasey
Paul Creasey

Reputation: 28834

asp mvc 2 structure map not working when deployed

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 :/

Upvotes: 1

Views: 1917

Answers (1)

Paul Creasey
Paul Creasey

Reputation: 28834

Self answer!

The problem was that the constructor of my datacontext was throwing because the database domain name wasn't fully qualified and while my pc resolved it, the server could not.

The inner exception containing the information wasn't showing on the error page!

:)

Upvotes: 3

Related Questions