I'm using StructureMap
at the moment, generally with convention-based (Scan()
) auto-configuration, and I'm looking to add decorator-based caching into the pipeline.
If I configure it manually that is fine, but Scan()
is just so convenient when you get lots of dependencies... I'm toying with noting cache suggestions on the interface(s), for example:
public interface IFoo {
[CacheDuration(20)] // cache for 20 minutes
string[] DoSomethingReusable();
SomeType DoSomethingNonReusable(int key); // not cached
}
with the idea being that by adding a custom "convention" to StructureMap
's scanning (pretty easy) it can spot that one-or-more methods are decorated for caching, and automatically inject a generated caching decorator into that type's pipeline (generating a cache key from the interface/method name and parameter values).
On the plus side it makes adding caching very painless - just decorate the interface a little; but is is a code smell? And/or am I duplicating something that is already solved?