title: How do I use Unity DI to load an assembly with dependencies and then register the internals
body: <p>I've got a asp.net mvc 3 web application that has plugin assemblies that implement system dependent EFcontexts and services.</p>
  
  <p>For example,  I've got an assembly that looks generically like the following:</p>
  
  <pre><code>System1Controller : IController // from System.Web.Mvc
  
  ISystem1Service {
      IList&lt;System1Type&gt; GetOperation(string something);
  }
  
  System1Service : ISystem1Service 
  {
      private ISystem1Entities context;
      public System1Service(ISystem1Entities context)
      {
          this.context = context;
      }
  }
  
  ISystem1Entities
  {
      IDbSet&lt;System1Type&gt; Operations { get; set; }
  }
  
  System1Entities : DbContext, ISystem1Entities
  </code></pre>
  
  <p>Using the Unity Bootstrapper and calling Bootstrapper.Initialize() works with the following BuildUnityContainer() implementation</p>
  
  <pre><code>private static IUnityContainer BuildUnityContainer()
  {
      var theContainer = new UnityContainer();
      var connectionString = ConfigurationManager.ConnectionStrings["WebAppConnectionString"];
      if (connectionString == null)
      {
          throw new ApplicationException("The ConnectionString is not defined.");
      }
  
      // register all your components with the container here
      // it is NOT necessary to register your controllers
      theContainer.RegisterType&lt;ISystem1Entities, System1Entities&gt;(
          new HierarchicalLifetimeManager(), 
          new InjectionConstructor(connectionString.ConnectionString));
  
      theContainer.RegisterType&lt;ISystem1Service, System1Service&gt;();
  
      var factory = new UnityControllerFactory(theContainer);
      ControllerBuilder.Current.SetControllerFactory(factory);
  
      return theContainer;
  }
  </code></pre>
  
  <p>I want to refactor the bootstrapper so that I can load 'unknown' at compile time assemblies, register the types that are contained in them and allow the web application to reference the controller, services, contexts as needed.</p>
  
  <p>I've looked at the <a href="http://autoregistration.codeplex.com/" rel="nofollow">Unity AutoRegistraion</a> project and it appears to be getting me in the neighborhood of the implementation that I want, but I'm not sure how to implement the following idea:</p>
  
  <pre><code>BootStrapper.BuildUnityConfiguration
      Initialize Container
      RegisterMyAssemblies()
  </code></pre>
  
  <p>I want the 'RegisterMyAssemblies' process to register a wildcard list of assemblies, then proceed to register the types within each individual assembly.  Any suggestions?</p>