Query container for configuration?

Jul 24, 2008 at 1:42 AM
Is there a mechanism for querying the container to retrieve configuration information?  I.e., I'd like to find out at runtime what implementation type a particular service interface has been mapped to via configuration or registration (including named mappings). I could read the unity configuration section directly but this could require multiple lookups to resolve alias' so I was wondering if there was an easier way.

Jul 28, 2008 at 11:26 PM
Hi gbraven,  have you considered retrieving the type info to satisfy your requirement?   In the following example I do a ResolveAll() but you could just as easily apply this concept to an object.


IUnityContainer container = new UnityContainer()
     .RegisterType<IDoSomething, GenericService>("GenericService")
IDoSomething, SpecializedService>("SpecializedService")
IDoSomething, BothServices>("BothServices");



IEnumerable<IDoSomething> somethingList = container.ResolveAll<IDoSomething>();
foreach (IDoSomething foundSomething in somethingList)
     Type somethingType = foundSomething.GetType();

The above generates the following information:


TYPE-INFO: GenericService            LTM.Service.GenericService                 LTM, Version=, Culture=neutral, PublicKeyToken=null
TYPE-INFO: SpecializedService     LTM.Service.SpecializedService           LTM, Version=, Culture=neutral, PublicKeyToken=null
TYPE-INFO: BothServices              LTM.Service.BothServices                    LTM, Version=, Culture=neutral, PublicKeyToken=null