Suppose I have a repository that returns a Post s list. The repository interface has a GetAll() method that does what it offers.
Now, guided by the theory that I should not put the domain logic in the repository, I want to intercept calls to the specific GetAll() method so that I can add the following logic to the result of GetAll() :
return GetAll().OrderByDescending(p => p.Posted).ToList();
The reason I want to intercept this is because (1) I do not want the client to not call the extension method ( OrderByDescending or some unnecessary wrapper of this), I want it to be called every time and (2 ) I do not want all my specific implementations to have to remember in order to get the result of GetAll() - I want this logic to be in one place external to any repository.
What is the easiest way to do this?
I already use StructureMap , so if I can intercept this, it could be a low cost option. But I don't think SM intercepts method calls, just instantiating an object?
Do I need to go to proxy or mixin template? Do I need to go all in with a dynamic proxy lock? Or is there another method I should consider, or perhaps a combination?
I am really interested in the specific sentence to my example above. I am new to AOP, so please be careful.
mixins aop structuremap interceptor castle-dynamicproxy
Matt kocaj
source share