title: Component Registration Exception with windsor
body: <p>I am trying to register a new component in my mvc application using windsor..</p>
  
  <p>First, I referenced to all windsors dlls..</p>
  
  <p>Then I used this code:</p>
  
  <pre><code>public class WindsorControllerFactory : DefaultControllerFactory
  {
      WindsorContainer container;
  
      public WindsorControllerFactory()
      {
          container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
  
          //Registers all components as transient.
          var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes()
                                where typeof(IController).IsAssignableFrom(t)
                                select t;
  
          foreach(Type t in controllerTypes)
          {
              container.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient);//Exception thrown here
          }
      }
  
      protected  virtual IController GetControllerInstance(Type controllerType)
      {
          return (IController)container.Resolve(controllerType);
      }
  }
  </code></pre>
  
  <p>Exception:</p>
  
  <blockquote>
    <p>[ComponentRegistrationException: Component SportsStore.Controllers.ProductController could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.]
       Castle.MicroKernel.SubSystems.Naming.DefaultNamingSubSystem.Register(IHandler handler) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\MicroKernel\SubSystems\Naming\DefaultNamingSubSystem.cs:237
       Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.RegisterHandler(String name, IHandler handler, Boolean skipRegistration) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:720
       Castle.MicroKernel.DefaultKernel.RegisterHandler(String name, IHandler handler) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\MicroKernel\DefaultKernel.cs:713
       Castle.MicroKernel.DefaultKernel.AddComponent(String key, Type serviceType, Type classType, LifestyleType lifestyle, Boolean overwriteLifestyle) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\MicroKernel\DefaultKernel_ObsoleteAPI.cs:106
       Castle.MicroKernel.DefaultKernel.AddComponent(String key, Type classType, LifestyleType lifestyle, Boolean overwriteLifestyle) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\MicroKernel\DefaultKernel_ObsoleteAPI.cs:59
       Castle.Windsor.WindsorContainer.AddComponentLifeStyle(String key, Type classType, LifestyleType lifestyle) in c:\BuildAgent\work\9834359f44c23fee\src\Castle.Windsor\Windsor\WindsorContainer_ObsoleteAPI.cs:94
       WindsorControllerFactory..ctor() in D:\Call.of.Duty.Modern.Warfare.3-RELOADED\SportsStore\SportsStore\SportsStore\WindsorControllerFactory.cs:33
       SportsStore.MvcApplication.Application_Start() in D:\Call.of.Duty.Modern.Warfare.3-RELOADED\SportsStore\SportsStore\SportsStore\Global.asax.cs:31</p>
  </blockquote>
  
  <p>I modified the web.config as such:</p>
  
  <pre><code> &lt;configSections&gt;
      &lt;section name="castle"
      type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
  Castle.Windsor" /&gt;
      &lt;!-- ... leave all the other section nodes as before ... --&gt;
    &lt;/configSections&gt;
  
  
    &lt;castle&gt;
      &lt;components&gt;
      &lt;/components&gt;
    &lt;/castle&gt;
  </code></pre>
  
  <p>and in the global asax file, I added this line:</p>
  
  <pre><code>protected void Application_Start()
  {
      AreaRegistration.RegisterAllAreas();
      ControllerBuilder.Current.SetControllerFactory(
          new WindsorControllerFactory());
      RegisterRoutes(RouteTable.Routes);
  }
  </code></pre>
  
  <p>The container/windsorContainer is empty as you can see from the web.config file, it has empty component..and I have only one controller to add--- Called ProductController..so how come it adds the controller twice?!!?</p>