ResolveAll<T>() does not resolve!

Nov 26, 2008 at 8:28 PM

I have the following config:

      <typeAlias alias="singleton"
           type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias alias="transient"
                 type="Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias alias="IApplicationModule"
           type="Framework.Interfaces.Snapin.IApplicationModule`1, Framework.Interfaces"/>
          <!-- Internal Mapping: Module from the Framework.Common.dll assembly -->
          <type type="IApplicationModule"
                mapTo="Framework.Common.Module, Framework.Common" name="Module">
            <lifetime type="transient" />
          <type type="IApplicationModule"
              mapTo="Framework.Common.Module2, Framework.Common.Tests" name="Module2">
            <lifetime type="transient" />

When I configure unity with this application file the Resolve("Module") or Resolve("Module2") successfully returns the modules. But when I do ResolveAll<IApplicationModule<MyType>>() then unity does not resolve the types and returns null instead. What am I doing wrong? It's really driving me crazy...

When I manually register my types on the container with RegisterType<IApplicationModule<MyType>, Module>("Module") and RegisterType<IApplicationModule<MyType>, Module2>("Module2") ResolveAll works!! Is this an implementation bug?

Thanks for your help

Nov 26, 2008 at 10:32 PM
Yeouch. Yeah, you've hit a (now obvious to me) limitation in the current implementation.

The ResolveAll method looks at an internal map of <type, name>. Once it finds the type, it loops over all the names, calling Resolve<type>(name) for each one.

That list doesn't know anything about open generics. Or more specifically, when you call ResolveAll, it goes looking for IApplicationModule<MyType>, and does NOT go looking for IApplicationModule<>. Which explains why it works when you register the closed generic types explicitly.

I'm going to put this in as a work item so we don't lose it.


Nov 26, 2008 at 10:33 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Nov 27, 2008 at 10:43 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?