title: Plugin Architecture with Simple Injector
body: <p>I am trying to use Simple Injector to create a plugin architecture that will allow me to configure a plugin <em>"abc"</em> (a tenant), and if I have provided <code>?tenant=abc</code> in the querystring of my request it will override a <em>"core"</em> plugin and use it's controllers instead.</p>
  
  <p>For example, if I have the following controller in "core":</p>
  
  <pre><code>public HomeController : Controller
  {
      public ActionResult Index()
      {
          ViewBag.Message = "This is core.";
          return View();
      }
  }
  </code></pre>
  
  <p>And, if I have specified <code>?tenant=abc</code>, then it should instead load the "abc" plugin controller:</p>
  
  <pre><code>public HomeController : Controller
  {
      public ActionResult Index()
      {
          ViewBag.Message = "This is abc.";
          return View();
      }
  }
  </code></pre>
  
  <p>The problem is, I am not quite sure where to start.  I have been reading the following posts, but still don't seem to have the "glue" to put all these pieces together.</p>
  
  <ul>
  <li><a href="https://simpleinjector.readthedocs.org/en/latest/advanced.html#registering-plugins-dynamically" rel="nofollow noreferrer">https://simpleinjector.readthedocs.org/en/latest/advanced.html#registering-plugins-dynamically</a></li>
  <li><a href="https://stackoverflow.com/questions/14436811/simple-injector-with-asp-net-mvc-4-load-controller-from-another-assembly">Simple Injector with asp.net mvc 4, load controller from another assembly</a></li>
  <li><a href="https://simpleinjector.codeplex.com/discussions/434951" rel="nofollow noreferrer">Multi-tenant IoC strategy</a></li>
  <li><a href="https://simpleinjector.codeplex.com/discussions/544023" rel="nofollow noreferrer">Tenant Injection in multi-tenancy scenario</a></li>
  </ul>
  
  <p>Can anyone provide me the slightest "quick-start" so I can put together a basic "hello world" the supports the functionality outlined above?</p>
  
  <p><strong>Edit:</strong> I imagine the solution will be similar to this (Autofac's multi-tenant implementation):</p>
  
  <pre><code>// First, create your application-level defaults using a standard 
  // ContainerBuilder, just as you are used to. 
  var builder = new ContainerBuilder(); 
  builder.RegisterType&lt;Consumer&gt;().As&lt;IDependencyConsumer&gt;().InstancePerDependency();
  builder.RegisterType&lt;BaseDependency&gt;().As&lt;IDependency&gt;().SingleInstance();
  var appContainer = builder.Build();  
  
  // Once you've built the application-level default container, you 
  // need to create a tenant identification strategy. 
  var tenantIdentifier = new MyTenantIdentificationStrategy();  
  
  // Now create the multitenant container using the application 
  // container and the tenant identification strategy. 
  var mtc = new MultitenantContainer(tenantIdentifier, appContainer);  
  
  // Configure the overrides for each tenant by passing in the tenant ID 
  // and a lambda that takes a ContainerBuilder. 
  mtc.ConfigureTenant('1', b =&gt; b.RegisterType&lt;Tenant1Dependency&gt;().As&lt;IDependency&gt;().InstancePerDependency()); 
  mtc.ConfigureTenant('2', b =&gt; b.RegisterType&lt;Tenant2Dependency&gt;().As&lt;IDependency&gt;().SingleInstance());  
  
  // Now you can use the multitenant container to resolve instances. 
  // Resolutions will be tenant-specific. 
  var dependency = mtc.Resolve&lt;IDependency&gt;();
  </code></pre>
  
  <ul>
  <li>Ref. <a href="http://www.paraesthesia.com/archive/2010/07/28/introducing-autofaccontrib.multitenant-multitenant-dependency-injection-with-autofac.aspx/" rel="nofollow noreferrer">http://www.paraesthesia.com/archive/2010/07/28/introducing-autofaccontrib.multitenant-multitenant-dependency-injection-with-autofac.aspx/</a></li>
  <li>Ref. <a href="https://code.google.com/p/autofac/wiki/MultitenantIntegration" rel="nofollow noreferrer">https://code.google.com/p/autofac/wiki/MultitenantIntegration</a></li>
  </ul>
  
  <p>Is there a way to do this sort of thing with SimpleInjector?</p>