所以我有一个简单的问题(我认为)。
如何使用Autofac对FilterAttribute执行Property Injection?
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
中一样。
答案 0 :(得分:1)
确保在容器构建器上调用RegisterFilterProvider方法,它将负责其余的工作。
http://code.google.com/p/autofac/wiki/Mvc3Integration#Filter_Attribute_Property_Injection