Can someone help me with this StructureMap error i'm getting?

Posted by Pure.Krome on Stack Overflow See other posts from Stack Overflow or by Pure.Krome
Published on 2010-05-10T05:24:50Z Indexed on 2010/05/10 5:28 UTC
Read the original article Hit count: 340

Hi folks,

I'm trying to wire up a simple ASP.NET MVC2 controller class to my own LoggingService.

Code compiles fine, but I get the following runtime error :-

{"StructureMap Exception Code:  202
No Default Instance defined for PluginFamily System.Type, mscorlib, 
    Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"}

what the? mscorlib ????

Here's some sample code of my wiring up ..

protected void Application_Start()
{
    MvcHandler.DisableMvcResponseHeader = true;

    BootstrapStructureMap();
    ControllerBuilder.Current.SetControllerFactory(
        new StructureMapControllerFactory());

    RegisterRoutes(RouteTable.Routes);
}

private static void BootstrapStructureMap()
{
    ObjectFactory.Initialize(x => 
        x.For<ILoggingService>().Use<Log4NetLoggingService>());
}

and finally the controller, simplified for this question ...

public class SearchController : Controller
{
    private readonly ILoggingService _log { get; set; }

    public SearchController(ILoggingService loggingService) : 
        base(loggingService)
    {
         // Error checking removed for brevity.
        _log = loggingService; 
        _log.Tag = "SearchController";
    }
...
}

and the structuremap factory (main method), also way simplified for this question...

protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { IController result = null;

if (controllerType != null)
{
    try
    {
        result = ObjectFactory.GetInstance(controllerType) as Controller;
    }
    catch (Exception exception)
    {
        if (exception is StructureMapException)
        {
            Debug.WriteLine(ObjectFactory.WhatDoIHave());
        }
    }
}

}

hmm. I just don't get it.

StructureMap version 2.6.1.0 ASP.NET MVC 2.

Any ideas?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about structuremap