title: MediatR with ASP.NET Core DI
body: <p>I'm playing around with the new ASP.NET Core and are currently creating a API that I want to call from a JavaScript frontend.</p>
  
  <p>I want to use the mediator pattern to reduce the coupling, and I have found the Library <a href="https://github.com/jbogard/MediatR" rel="noreferrer">MediatR</a> from Jimmy Bogard.</p>
  
  <p>My problem consist in wiring it up using the build in DI, I have tried looking at the <a href="https://github.com/jbogard/MediatR/tree/master/samples" rel="noreferrer">examples</a>, but can't see to crack how it binds into the ConfigureServices method in the startup class. </p>
  
  <p>Do anybody have any insight?</p>
  
  <p>UPDATE: I got it working, from my ConfigureService method:</p>
  
  <pre><code>services.AddScoped&lt;SingleInstanceFactory&gt;(p =&gt; t =&gt; p.GetRequiredService(t));
  
  services.Scan(scan =&gt; scan
          .FromAssembliesOf(typeof(IMediator), typeof(MyHandler.Handler))
          .AddClasses()
          .AsImplementedInterfaces());
  </code></pre>