MVC3 / Structure Map 2.6.2 DI自定义控制器工厂问题(MVC3 / Structure Map 2.6.2 DI custom controller factory prob

编程入门 行业动态 更新时间:2024-10-26 20:28:47
MVC3 / Structure Map 2.6.2 DI自定义控制器工厂问题(MVC3 / Structure Map 2.6.2 DI custom controller factory problem)

我将非参数类作为模型传递给控制器​​中的视图时出现问题。

我最近从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

更多推荐

本文发布于:2023-08-07 14:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464770.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   控制器   工厂   Structure   Map

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!