【发布时间】:2012-08-07 18:37:41
【问题描述】:
所以我有一个简单的问题(我认为)。
如何使用 Autofac 对 FilterAttribute 进行属性注入?
Public Class TestFilterAttribute
Inherits ActionFilterAttribute
Public Property Service As IMyService
Public Overrides Sub OnActionExecuting(filterContext As System.Web.Mvc.ActionExecutingContext)
** I need to get to the IMyService here **
Dim val = Service.GetValue()
MyBase.OnActionExecuting(filterContext)
End Sub
End Class
我已经在容器中注册了服务:
builder.RegisterType(Of MyService).As(Of IMyService)().InstancePerHttpRequest()
或者也许我的做法是错误的。我希望能够注入过滤器属性。
另外,当使用Register时,你是否也必须使用.As?比如RegisterType。
【问题讨论】:
标签: asp.net-mvc-3 autofac property-injection