How do I resolve Dependency Injection in MVC Filter attributes

前端 未结 4 533
灰色年华
灰色年华 2021-02-07 15:36

I have a custom attribute class derived from AuthorizationAttribute, which performs custom security on controller actions. The OnAuthorizationCore method depends on various othe

4条回答
  •  春和景丽
    2021-02-07 16:28

    There's no straight-forward way to do this prior to MVC2. There is an interesting technique detailed here: http://www.mattlong.com.au/?p=154. I'd suggest using the Common Service Locator to abstract over this and locate your DI container.

    If you're using MVC 3 then you can use MVC Service Location

提交回复
热议问题