DI: Injecting the ActionFilterAttribute (ASP.NET MVC)

I was wondering if a specific implementation could be injected ActionFilterAttribute

using an IoC container.

For example, imagine you are creating a class TransactionAttribute

[Transaction]

You use this to decorate an action that needs to be transacted at the save level. But the implementation details of the attribute will be tied to the persistence technology being used, and strictly speaking, your controller doesn't need to know about this, and you might want to change it.

What I would like to do is define some kind of interface TransactionAttribute

and then include the IoC container in the correct implementation. Therefore, according to my actions, I only need to specify:

 [Transaction]
 public ActionResult SomeAction()
 {
     ....
 }

      

... and the IoC will inject the correct implementation depending on the configuration (for example, something like NHibernateTransactionAttribute

or SomeOtherORMTransactionAttribute

).

Is it possible? Has anyone done this?

+2


a source to share


1 answer


How to use Windsor to inject dependencies into ActionFilterAttributes , you should give an idea of ​​how to achieve this.



+2


a source







All Articles