Generic registration in Windsor with UsingFactoryMethod
<p>We currently have code that looks something like below, with a factory being injected in to a lot of classes, which then call the factory to get an instance of what they want.</p>

<pre><code>public class Service
{
     public Service(IFactory factory)
     {
          _car = factory.GetCar&lt;Entity&gt;();
     }
}

public class Car : ICar
{
}

public interface IFactory
{
    ICar&lt;TEntity&gt; GetCar&lt;TEntity&gt;();

    IBoat&lt;TEntity&gt; GetBoat&lt;TEntity&gt;();
}

public class Factory : IFactory
{
    ConnectionDetails _connectionDetails;    

    public Factory(ConnectionDetails connectionDetails)
    {
        _connectionDetails = connectionDetails;
    }

    TEntity GetCar&lt;TEntity&gt;()
    {
        var car = new Car&lt;TEntity&gt;(_connectionDetails);
        car.Initialize();
        return car;
    }
}
</code></pre>

<p>I was hoping to be able to create a solution that would allow for request a dependency directly on the <code>Car&lt;TEntity&gt;</code> without needing to go through the factory first.</p>

<p>Below is an example of installing for a single <code>TEntity</code>, but how would I set this up to be generic?</p>

<p>I've tried using open generics, but I can't see how I can get the correct return type out of <code>.UsingFactoryMethod()</code>.</p>

<p>I know I can get the <code>RequestedType</code> out of the <code>CreationContext</code>, but I don't see how I can use that to solve this problem.</p>

<pre><code>public class Installer : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(
                    Component.For&lt;ICar&lt;TEntity&gt;&gt;().UsingFactoryMethod(
                        kernel =&gt;
                        {
                            var factory = kernel.Resolve&lt;IFactory&gt;();
                            return factory.GetCar&lt;TEntity&gt;();
                        }));
    }
}
</code></pre>