title: Castle windsor chained dependency with multiple implementations of interface in ASP.NET MVC
body: <p>I have a setup that looks like this:</p>
  
  <p>Controller > IService > IUnitOfWork > IContext > IConnectionStringHelper</p>
  
  <p>In almost all cases I want IConnectionStringHelper to be resolved by ConnectionStringHelper, but when i use <em>ISpecialService</em>, I want to use <em>SpecialConnectionStringHelper</em> as the resolver.</p>
  
  <p>I use a IExceptionFilter to log and redirect the user by implementing the <em>OnException</em>, and in this method I resolve ISpecialService. This is a hook to catch all unhandled exceptions that might occur. </p>
  
  <p>What happens is that I call a controller and that controller gets everything injected as it should. If an error occures, the OnException method gets called and in this method i try to resolve my SpecialService</p>
  
  <pre><code>var spc = WindsorConfig._windsorContainer.Resolve&lt;ISpecialService&gt;();
  int? errandId = spc.CreateErrandFromError(message, innerMessage, StackTrace);
  </code></pre>
  
  <p>The problem I'm facing is that when I now resolve the ISpecialService, the chain is already resolved but with the wrong implementation of IConnectionStringHelper. I have tried to use the <strong>DependsOn</strong> but I'm not sure how to make the <strong>IConnectionStringHelper</strong> depend on <strong>IService</strong> (ISpecialService). I have tried some variations and latest I tried was this</p>
  
  <pre><code>Component.For&lt;IConnectionStringHelper&gt;().ImplementedBy&lt;ConnectionStringHelper&gt;().LifeStyle.PerWebRequest,
  Component.For&lt;IConnectionStringHelper&gt;().ImplementedBy&lt;SpecialConnectionStringHelper&gt;().LifeStyle.Transient,
  Component.For&lt;ISpecialService&gt;().ImplementedBy&lt;SpecialService&gt;().LifeStyle.Transient
     .DependsOn(Dependency.OnComponent&lt;IUnitOfWork, UnitOfWork&gt;())
     .DependsOn(Dependency.OnComponent&lt;IContext, Context&gt;())
     .DependsOn(Dependency.OnComponent&lt;IConnectionStringHelper, SpecialConnectionStringHelper&gt;())
  </code></pre>
  
  <p>As the <strong>ISpecialService</strong> doesn't have the <strong>IConnectionStringHelper</strong> as a directly injected interface, I can see how this setup might not work, but is it possible, and how can I achieve it?</p>