1

I'm having problems with passing non-parameterless classes as models to a view in a controller.

I recently moved from Structure Map 2.5.3 to 2.6.2. Everything worked fine in 2.5.3 nad it doesn't work anymore in 2.6.2. Here is my Custom Controller factory:

public class StructureMapControllerFactory : DefaultControllerFactory
{
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
    {
        try
        {
            return ObjectFactory.GetInstance(controllerType) as Controller;
        }
        catch (StructureMapException)
        {
            Debug.WriteLine(ObjectFactory.WhatDoIHave());
            throw;
        }
    }
}

And wiring it:

ControllerBuilder.Current.SetControllerFactory(typeof(StructureMapControllerFactory));

My Custom model binder throws an exception: http://screencast.com/t/xZDNAAmM

What could be a problem?

Nebojsa Veron
  • 1,545
  • 3
  • 19
  • 36

1 Answers1

0

I don't think this has anything to do with your DI container. When instance is null the call to your modelbinder is made and probably it tries to create a new instance of modelType which is impossible as that doesn't have a parameterless constructor.

I think you just added a constructor parameter to the constructor of your modelType

thekip
  • 3,660
  • 2
  • 21
  • 41
  • Yes I did, and that's what I'm trying to solve. My modelType dosn't have parameterless constructor, and that's what Structure Map custom controller factory should take care of since I use dependency injection in the constructor of that class? – Nebojsa Veron Aug 17 '11 at 09:24
  • But you're not constructing modeltype (or at least not the one used in your modelbinder) through structuremap. – thekip Aug 17 '11 at 11:53