2

I was wondering if it is possible to inject a particular ActionFilterAttribute implementation using a IoC container.

For example, imagine you create a TransactionAttribute class [Transaction]

You use this to decorate action which should be wrapped in a transaction in the persistence layer. But implementation details of the attribute will be tied to the persistence tech you are using, and strictly speaking, your controller should not know about this, and you might want to swap this out.

What I would like to do, is define some kind of TransactionAttribute interface, and then have my IoC container inject the correct implementation. So on my actions I only need specify:

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

...and the IoC will inject the correct implementation depending on config (eg. something like NHibernateTransactionAttribute, or SomeOtherORMTransactionAttribute).

Is this possible? Has anyone done it?

1 Answer 1

2

How do I use Windsor to inject dependencies into ActionFilterAttributes should give you an idea how to achieve this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.