title: What's the simplest way to intercept a method call for added functionality?
body: <p>Suppose i have a repository that returns a list of <code>Post</code>s. The repository interface has a <code>GetAll()</code> method which does what it suggests.</p>
  
  <p>Now in keeping with the theory that i shouldn't be putting domain logic in the repository, i want to intercept calls to the concrete <code>GetAll()</code> method such that i can add the following logic to the <code>GetAll()</code> result:</p>
  
  <pre><code>return GetAll().OrderByDescending(p =&gt; p.Posted).ToList();
  </code></pre>
  
  <p>The reason i want to intercept this is because (1) i don't want to have the client remember to call an extension method (<code>OrderByDescending</code> or some useless wrapper of that), i want it called every time and (2) i don't want to have all my concrete implementations have to remember to order the <code>GetAll()</code> result - i want this logic in a single place external to any repository.</p>
  
  <p>What's the easiest way to do this?</p>
  
  <p>I'm already using <a href="http://structuremap.net/structuremap/" rel="noreferrer">StructureMap</a> so if i can intercept with this it might be a low cost option. But i don't think SM intercepts method calls, just the creation of the object instance?</p>
  
  <p>Do i need to go to a <a href="http://msmvps.com/blogs/jon_skeet/archive/2007/02/27/wacky-ideas-1-inheritance-is-dead-long-live-mix-ins.aspx" rel="noreferrer">proxy or mixin</a> pattern? Do i need to go all-in with Castle <a href="http://kozmic.pl/dynamic-proxy-tutorial/" rel="noreferrer">Dynamic Proxy</a>? Or is there <a href="http://ayende.com/Blog/archive/2007/07/02/7-Approaches-for-AOP-in-.Net.aspx" rel="noreferrer">another method</a> i should consider or perhaps a combination?</p>
  
  <p>I'm really interested in a concrete suggestion to my particular example above. I'm novice to AOP so please be gentle.</p>