我将非参数类作为模型传递给控制器中的视图时出现问题。
我最近从Structure Map 2.5.3迁移到2.6.2。 一切都运行良好的2.5.3,它在2.6.2中不再起作用。 这是我的自定义控制器工厂:
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; } } }接线:
ControllerBuilder.Current.SetControllerFactory(typeof(StructureMapControllerFactory));我的自定义模型绑定器抛出异常: http : //screencast.com/t/xZDNAAmM
可能有什么问题?
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?
最满意答案
我不认为这与您的DI容器有任何关系。 当instance为null时,会对modelbinder进行调用,并且可能会尝试创建一个新的modelType实例,这是不可能的,因为它没有无参数构造函数。
我想你刚刚在你的modelType的构造函数中添加了一个构造函数参数
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
更多推荐
发布评论