C# Unity InjectionFactory not working
<p>I am using Unity as IOC and trying to inject an interface with a factory method which takes a interface as a parameter.</p>

<p>For some reason the configReader parameter in the factory method GetTitleParser(), is null and not getting the injected ConfigurationReader() instance.</p>

<p>When i place a debug point at the line in RegisterTypes method where the new InjectionFactory exists, ITitleParser is not showing as mapped to a proper mapped type.</p>

<p>can anyone help what am i doing wrong here?</p>

<p>Here is my code:</p>

<pre><code>public class UnityContainerBuilder
{
    public static IUnityContainer Build()
    {
        var container = new UnityContainer();
        RegisterTypes(container);
        return container;
    }

    public static void RegisterTypes(IUnityContainer container)
    {
        // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
        container.LoadConfiguration();
        container.RegisterType&lt;IConfigurationReader, ConfigurationReader&gt;();
        container.RegisterType&lt;ITitleParser&gt;(new InjectionFactory(c =&gt; ParserFactory.GetTitleParser()));            
    }
}

public class ParserFactory
{
    public static ITitleParser GetTitleParser(IConfigurationReader configReader=null)
    {
        if(configReader==null) configReader = new ConfigurationReader();

        /* rest of code here...*/

        return parser;
    }
}   
</code></pre>

<p>It works when i use the following code. Is this the right way to do this?</p>

<pre><code>    container.RegisterType&lt;IConfigurationReader, ConfigurationReader&gt;();
    container.RegisterType&lt;ITitleParser&gt;(new InjectionFactory(c =&gt;
                                                                {
                                                                    var configReader = c.Resolve&lt;IConfigurationReader&gt;();
                                                                    var parser = ParserFactory.GetTitleParser(configReader);
                                                                    return parser;
                                                                }));
</code></pre>