title: Unity to Resolve By Name
body: <p>I'm trying to get Unity to be my factory in a factory pattern, hence return different implementations of an Interface depending upon the named instance.  I have the following code</p>
  
  <p>public static class Factory
      {
          private static readonly IUnityContainer container;</p>
  
  <pre><code>    static Factory()
      {
          container = new UnityContainer();
          container
              .AddNewExtension&lt;EnterpriseLibraryCoreExtension&gt;()
              .AddNewExtension&lt;Interception&gt;()
              .RegisterType&lt;IInterceptionBehavior, LoggingBehaviour&gt;()
  
              //register the implemantation1
              .RegisterType&lt;IMessageFactory, implemantation1&gt;("implemantation1")
              .RegisterType&lt;IMessageFactory, implemantation1&gt;(new InjectionProperty("Server", ConfigurationManager.AppSettings["Server"]))
              .RegisterType&lt;IMessageFactory, implemantation1&gt;(new InjectionProperty("ServerPort", int.Parse(ConfigurationManager.AppSettings["Port"])))
              .RegisterType&lt;IMessageFactory, implemantation1&gt;(
                  new Interceptor&lt;InterfaceInterceptor&gt;(),
                  new InterceptionBehavior(container.Resolve&lt;IInterceptionBehavior&gt;()))
  
              //register the implemantation2
              .RegisterType&lt;IMessageFactory, implemantation2&gt;("implemantation2")
              .RegisterType&lt;IMessageFactory, implemantation2&gt;(new InjectionProperty("Server", ConfigurationManager.AppSettings["Server"]))
              .RegisterType&lt;IMessageFactory, implemantation2&gt;(new InjectionProperty("Port", int.Parse(ConfigurationManager.AppSettings["Port"])))
              .RegisterType&lt;IMessageFactory, implemantation2&gt;(
                  new Interceptor&lt;InterfaceInterceptor&gt;(),
                  new InterceptionBehavior(container.Resolve&lt;IInterceptionBehavior&gt;()))
              ;
      }
  
      /// Instantiates a data provider class
      public static T CreateFactory&lt;T&gt;(string name)
      {
          return container.Resolve&lt;T&gt;(name);
      }
  }
  </code></pre>
  
  <p>When I try to resolve the container by calling the CreateFactory method with "implemantation2" or "implemantation1" I get the following error:
   InvalidOperationException - The type String cannot be constructed. You must configure the container to supply this value.</p>
  
  <p>I don't know what I'm doing wrong any help would be greatly appreciated.</p>
  
  <p>Josh</p>