1

Is there a way to do dependency injection inside an outputcache attribute where I can check some things in a database before I return the cache or not?

[CustomOutputCache(CacheProfile = "Documents")]
        public virtual ActionResult Scoresheets(int? eventId, int? gameId)
        {
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
  • It's better to keep attributes passive as described [here](http://blog.ploeh.dk/2014/06/13/passive-attributes/) and [here](http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=98). – Steven Jul 24 '14 at 05:48

1 Answers1

0

This is probably an alternative approach...

I have not tried DI within a custom OutputCache attribute. But if you have tried and if there is no way to hook into the DI container, I would mimic the OutputCache attribute behavior in an Action Filter and use the DI within the action filter. You probably know it is very easy to inject dependencies to the action filter using a DI container.

Community
  • 1
  • 1
Spock
  • 7,009
  • 1
  • 41
  • 60