title: Strategy Pattern with ASP.Net Core DI
body: <p>While building my Rest API I stumbled across building a Cached Repository based on <a href="https://ardalis.com/building-a-cachedrepository-via-strategy-pattern" rel="nofollow noreferrer">this Article</a>.</p>
  
  <p><a href="https://ardalis.com/building-a-cachedrepository-via-strategy-pattern" rel="nofollow noreferrer">Building a CachedRepository via Strategy Pattern</a></p>
  
  <p>I liked the idea because the code seemed nice and dry. Therefore I went and gave it a shot and the Implementation was quite nice. </p>
  
  <p>However now I want to wire up my DI (the Standard Microsoft DI coming with ASP.Net Core and nothing fancy) and I am Facing some trouble there.</p>
  
  <p>Basically the problem is that I have multiple implementation of the same interface and the cached implementation takes a reference to the direct implementation like so:</p>
  
  <pre><code>public class CachedArticleRepository : IArticleRepository
  {
      public CachedArticleRepository(IArticleRepository article, IMemoryCache cache)
      {
          _article = article;
          _cache = cache;
      }
  }
  
  public class ArticleRepository : IArticleRepository
  {
      public ArticleRepository(IAmbientContextLocator locator)
      {
          _locator = locator;
      }    
  }
  </code></pre>
  
  <p>I use it in my service (as explained by the Article) like this:</p>
  
  <pre><code>public class DivisionService : IDivisionService
  {
      public DivisionService(IArticleRepository article)
      {
          _article = article;
      }
  }
  </code></pre>
  
  <p>My Question is now how can I configure the DI so that the Non Cached Variant is used for building the Cached Repository and the Cached Repository is used for everything else?</p>