This project is read-only.


ResolveAll<T>() does not resolve when called with registered open generics


<p>Hello</p> <p>&nbsp;</p> <p>I have the following config:</p> <p>&nbsp;</p> <p> &lt;typeAliases&gt;</p> <p> &lt;typeAlias alias=&quot;singleton&quot;</p> <p> type=&quot;Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity&quot; /&gt;</p> <p> &lt;typeAlias alias=&quot;transient&quot;</p> <p> type=&quot;Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity&quot; /&gt;</p> <p> &lt;typeAlias alias=&quot;IApplicationModule&quot;</p> <p> type=&quot;Framework.Interfaces.Snapin.IApplicationModule`1, Framework.Interfaces&quot;/&gt;</p> <p> &lt;/typeAliases&gt;</p> <p> &lt;containers&gt;</p> <p> &lt;container&gt;</p> <p> &lt;types&gt;</p> <p> &lt;!-- Internal Mapping: Module from the Framework.Common.dll assembly --&gt;</p> <p> &lt;type type=&quot;IApplicationModule&quot;</p> <p> mapTo=&quot;Framework.Common.Module, Framework.Common&quot; name=&quot;Module&quot;&gt;</p> <p> &lt;lifetime type=&quot;transient&quot; /&gt;</p> <p> &lt;/type&gt;</p> <p> &lt;type type=&quot;IApplicationModule&quot;</p> <p> mapTo=&quot;Framework.Common.Module2, Framework.Common.Tests&quot; name=&quot;Module2&quot;&gt;</p> <p> &lt;lifetime type=&quot;transient&quot; /&gt;</p> <p> &lt;/type&gt;</p> <p> &lt;/types&gt;</p> <p> &lt;/container&gt;</p> <p> &lt;/containers&gt;</p> <p>&nbsp;</p> <p>When I configure unity with this application file the Resolve(&quot;Module&quot;) or Resolve(&quot;Module2&quot;) successfully returns the modules. But when I do ResolveAll&lt;IApplicationModule&lt;MyType&gt;&gt;() then unity does not resolve the types and returns null instead. What am I doing wrong? It&#39;s really driving me crazy...</p> <p>&nbsp;</p> <p>When I manually register my types on the container with RegisterType&lt;IApplicationModule&lt;MyType&gt;, Module&gt;(&quot;Module&quot;) and RegisterType&lt;IApplicationModule&lt;MyType&gt;, Module2&gt;(&quot;Module2&quot;) ResolveAll works!! Is this an implementation bug?</p> <p>&nbsp;</p> <p>Thanks for your help</p> <p>&nbsp;</p> <p>Daniel</p>
Closed Mar 16, 2010 at 4:47 PM by
Fixed in 2.0 Beta 2.


LOBOMINATOR wrote Nov 27, 2008 at 7:14 AM

Thanks for your response. Is there a way to overcome this issue? I don't want to explicitly add all the module types somewhere in my code to the unity container... Do you have a solution for this issue?


izobr wrote Nov 6, 2009 at 5:47 PM

I see nobody takes care for this issue. But it is really affecting my project.
Actually fix is very simple and is all about five lines of code. Just change ResolveAll in UnityContainer.cs to this:
    public override IEnumerable ResolveAll(Type t)
        List names = new List(registeredNames.GetKeys(t));

        if (t.IsGenericType)
            Type tdef = t.GetGenericTypeDefinition();

        foreach (string name in names)
            yield return Resolve(t, name);
Relative discussion:

ctavares wrote Mar 8, 2010 at 6:03 PM

Fixed in Beta 2.