Injecting dependency into CustomAttribute using Castle Windsor

五迷三道 提交于 2019-11-28 06:57:15
BonyT

OK - this seems to be a duplicate of Database injection into a validation attribute with ASP MVC and Castle Windsor which has been answered.

Also How do I use Windsor to inject dependencies into ActionFilterAttributes.

Having read through the above, and the referenced articles - the key one for me is http://weblogs.asp.net/psteele/archive/2009/11/04/using-windsor-to-inject-dependencies-into-asp-net-mvc-actionfilters.aspx for anyone else who is interested.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!