MVC3/结构图2.6.2 DI自定义控制器工厂问题
我在将非无参数类作为模型传递到控制器中的视图时遇到问题。
我最近从 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为这与你的 DI 容器有任何关系。当实例为空时,会对模型绑定器进行调用,并且可能会尝试创建一个新的
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