views:

363

answers:

1

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

+1  A: 

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!

:)

Paul Creasey
An exception thrown by your type's ctor should be reflected as an inner exception within the StructureMap exception. I understand that searching for the inner exception can be a pain but StructureMap does a pretty good job regarding context about the problem it encounters. As you typically do not have too much logic in your ctors. People often run into throws not related to your type's ctors but things like SM needing configuration for an abstraction.
KevM
@KevM, thanks I guess that I need to install NLog or log4net, to get the full exception details, since the default one doesn't show inner exceptions. Do you know of an easy fix to get it showing inner exceptions by any chance?
Paul Creasey
Not really sure how to help without seeing the exception output for the problem you were having. I do not use any logging framework to figure out what is wrong with my StructureMap configuration. I often do write tests which greatly help me understand the problem.
KevM