There's this framework that I'm helping to design. There are some common tasks that should be done using some common components : Logging, Caching and raising events in particular.
I am not sure if it's better to use dependency injection and introduce all of these components to each service (as properties for example) or should I have some kind of meta data placed over each method of my services and use interception to do these common tasks?
Here's an example of both:
Injection:
public class MyService
{
public ILoggingService Logger{get;set;}
public IEventBroker EventBroker{get;set;}
public ICacheService Cache{get;set;}
public void DoSomething()
{
Logger.Log(myMessage);
EventBroker.Publish<EventType>();
Cache.Add(myObject);
}
}
and here's the other version:
Interception:
public class MyService
{
[Log("My message")]
[PublishEvent(typeof(EventType))]
public void DoSomething()
{
}
}
Here are my questions:
- Which solution is best for a complicated framework?
- If interception
wins, what are my options to interact with internal values of a method (to use with cache service for example?)? can I use other ways rather than attributes to implement this behavior? - Or maybe there can be other solutions to solve the problem?
