So let's say this is my greate setup:
And I want to log calls to the service without putting ugly logging lines inside the service or the calling object. How do I do this?
Well, you could go all the way with Ninject Interceptors - the way I normally do it:
Code here. Get both Nuget.Exensions.Interceptors and either the Castle or LinFu proxy package ( don't forget those ! ).
OK - that's nice - that's elegant. But I realised that there's also a more lightweight alternative to this - writing a passthroughproxy:
The LogAspect overrides the call - logs the call and calls its base method to propagate the call down to MyService.
Hooking this up goes as follows:
The reason I built something like this, is because I was trying to listen in on events. You can do the same thing for events, where you build a pass through proxy that propagates the events, but also logs. And I couldn't listen in on these with interceptors.
Code here
No comments:
Post a Comment