所以我有一个简单的问题(我想)。
如何使用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
.
确保在
容器生成器上调用 RegisterFilterProvider 方法,它将负责其余的工作。
http://code.google.com/p/autofac/wiki/Mvc3Integration#Filter_Attribute_Property_Injection