1
我想依赖注入使用Spring.Net在ASP.NET MVC的属性,我的属性是这样的(注意,这是所有的伪代码,我刚才输入)...Spring.Net和属性注入
public class InjectedAttribute : ActionFilterAttribute
{
private IBusinessLogic businessLogic;
public InjectedAttribute(IBusinessLogic businessLogic)
{
this.businessLogic = businessLogic;
}
public override void OnActionExecuting(ActionExecutedContext filterContext)
{
// do something with the business logic
businessLogic.DoSomethingImportant();
}
}
我正在使用控制器工厂来创建也注入了各种业务逻辑对象的控制器。我是从这样的IoC容器获取控制器...
ContextRegistry.GetContext().GetObject("MyMVCController");
我配置我的控制器,像这样通过在业务逻辑
<object name="MyMVCController" type="MyMVC.MyMVCController, MyMVC">
<constructor-arg index="0" ref="businessLogic" />
</object>
是否有配置注射的方式的属性?我真的不希望把这个变成我的属性...
public class InjectedAttribute : ActionFilterAttribute
{
private IBusinessLogic businessLogic;
public InjectedAttribute(IBusinessLogic businessLogic)
{
this.businessLogic = ContextRegistry.GetContext().GetObject("businessLogic");
}
....
它的MVC 1,所以我将无法使用自定义筛选器提供程序... – Gaz
这工作很好,最佳答案:) – Gaz