開始有兩件事。Autofac 2.6和Orchard 1.6 - 行動過濾器施工注塑
- 我想實現一個動作過濾器,記錄時和動作開始,當它結束
- 我深知在Autofac 3.0 .AsActionFilter()方法,但...
這個項目使用的是Orchard 1.6,它被稱爲與autofac 2.6.xxx兼容。我們不希望在此時升級到Autofac 3.0,因此我們無法使用.AsActionFilter()選項。
另一種選擇是設置過濾器(它擴展了ActionFilterAttribute)作爲我們的基礎控制器(從中所有其他繼承btw)屬性。問題是,該過濾器本身有兩個依賴:
- 保存上下文
- 的ILoggingService的實現信息我們自己的服務
我不能找到一種方法來將這些注入到班級負責人的實際財產中。有沒有人知道在註冊期間通過Autofac的某些功能的[Attribute]行本身來實現這一目標的方法?
的ActionFilterAttribute:
public class GRMSActionLoggingFilter : ActionFilterAttribute {
private readonly IGRMSCoreServices _grmsCoreServices;
private readonly ILoggingService _loggingService;
public GRMSActionLoggingFilter(IGRMSCoreServices grmsCoreServices, ILoggingService loggingService) {
_grmsCoreServices = grmsCoreServices;
_loggingService = loggingService;
}
public GRMSActionLoggingFilter() { }
public override void OnActionExecuting(ActionExecutingContext actionContext) {...}
public override void OnActionExecuted(ActionExecutedContext actionContext) {...}
}
分配屬性的基本控制器:
// This currently compiles but will fail during run time as the IGRMSCoreSerivces and ILoggingService will both be null. Need to property inject these services somehow.
[GRMSActionLoggingFilter]
任何人有任何想法,以實現這一目標?
正在更新到1.7(當前1.x分支)爲你好嗎?它在Autofac 3.0上運行。 – 2013-05-07 20:23:53
目前還不是一個真正的選擇,因爲我們正在接近客戶端的測試版。 我們正考慮在截止日期過後執行升級,但我們(請閱讀,我的技術主管= P)在此之前還想要採取行動登錄。 – 2013-05-08 08:16:10