title: In Castle Windsor 3, override an existing component registration in a unit test
body: <p>I am attempting to use Castle Windsor in my automated tests like so:</p>
  
  <p>On every test:</p>
  
  <ul>
  <li>The <code>Setup()</code> function creates a Windsor container, registering default implementations of each component</li>
  <li>The <code>Test</code> function access the components via the method <code>IWindsorContainer.Resolve&lt;T&gt;</code>, and tests their behavior</li>
  <li>The <code>TearDown()</code> function disposes of the Windsor container (and any created components)</li>
  </ul>
  
  <p>For example, I might have 15 tests which accesses components which indirectly results in the creation of an <code>IMediaPlayerProxyFactory</code> component. The <code>SetUp</code> function registers a good-enough implementation <code>IMediaPlayerProxyFactory</code>, so I don't have the maintenance burden of registering this in each of the 15 tests.</p>
  
  <p>However, I'm now writing a test <code>Test_MediaPlayerProxyFactoryThrowsException</code>, confirming my system elegantly handles an error from the <code>IMediaPlayerProxyFactory</code> component. In the test method I've created my special mock implementation, and now I want to inject it into the framework: </p>
  
  <pre class="lang-c# prettyprint-override"><code>this.WindsorContainer.Register(
                                   Component.For&lt;IMediaPlayerProxyFactory&gt;()
                                            .Instance(mockMediaPlayerProxyFactory)
                                );
  </code></pre>
  
  <p>But Windsor throws a <code>Castle.MicroKernel.ComponentRegistrationException</code>, with the message "There is already a component with that name."</p>
  
  <p>Is there any way that I can make my <code>mockMediaPlayerProxyFactory</code> be the default instance for the <code>IMediaPlayerProxyFactory</code>, discarding the component that's already registered?</p>
  
  <p><hr />
  According to the <a href="http://stw.castleproject.org/Windsor.Whats-New-In-Windsor-3.ashx?NS=Windsor">documentation</a>, Castle Windsor 3 allows for registration overrides, but I could only find one example:</p>
  
  <pre class="lang-c# prettyprint-override"><code>Container.Register(
      Classes.FromThisAssembly()
          .BasedOn&lt;IEmptyService&gt;()
          .WithService.Base()
          .ConfigureFor&lt;EmptyServiceA&gt;(c =&gt; c.IsDefault()));
  </code></pre>
  
  <p><code>ConfigureFor</code> is a method of the <code>BasedOnDescriptor</code> class. In my case I'm not using the <code>FromDescriptor</code> or <code>BasedOnDescriptor</code>. </p>