dependency-injection - StructureMap MVC 5 html.Action 问题

标签 dependency-injection asp.net-mvc-5 inversion-of-control structuremap

我正在尝试使用 @Html.Action("ActionName","controllerName") 从我的 View 中调用操作.但是我的页面无法加载并出现以下错误:

A single instance of controller 'Web.Areas.Area1.Controllers.ActionController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.



我正在使用结构图进行依赖注入(inject)。请帮助我我错过了什么。

最佳答案

您需要添加
x.For<{Your controller name}>().AlwaysUnique();
在 IoC.cs 文件中。这应该为项目中的每个 Controller 完成。

更多详情请查看this link .

关于dependency-injection - StructureMap MVC 5 html.Action 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24743215/

相关文章:

serialization - Spring中的依赖注入(inject)和序列化对象

c# - ASP.NET MVC 模型与动态 View 模型绑定(bind)

azure - 虚拟目录部署的内部错误

c# - 为什么我需要 ToList() 来避免处理上下文错误?

inversion-of-control - 什么时候使用 IoC 合适?

asp.net-mvc - Ninject 获取实例时出现问题

java - 使用 Spring 实现工厂方法

java - 如何像在 Spring 中那样在 Dagger 中注入(inject)列表或集合?

java - Spring 3.0 中的 FactoryBeans 和基于注解的配置

asp.net-mvc - 构建中等大小的 asp mvc - 使用 ninject 和创建对象