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