Injecting dependency into CustomAttribute using Castle Windsor

前端 未结 2 1750
渐次进展
渐次进展 2020-12-08 22:23

In my ASP.Net MVC application I have implemented a Custom ActionFilter to Authorize users.

I use CastleWindsor to provide dependency injection into all of the contro

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 23:09

    You can't. Attributes are metadata. Putting behaviour into them is wrong. Putting dependencies is even worse.

    Use your attribute as marker to denote objects to which you want to apply the behavior and implement the behavior elsewhere.

    In MVC elsewhere usually means a custom action invoker that uses data from the attribute to provide the behavior you need.

提交回复
热议问题