2012-08-07 50 views
0

所以我有一個簡單的問題(我認爲)。使用Autofac的物業注入

你如何使用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一樣。

回答