Query container for configuration?

Jul 24, 2008 at 12: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.

Thanks.
Jul 28, 2008 at 10: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()
     .AddNewExtension<
SimpleEventBrokerExtension>()
     .RegisterType<IDoSomething, GenericService>("GenericService")
     .RegisterType<
IDoSomething, SpecializedService>("SpecializedService")
     .RegisterType<
IDoSomething, BothServices>("BothServices");

 

 

IEnumerable<IDoSomething> somethingList = container.ResolveAll<IDoSomething>();
foreach (IDoSomething foundSomething in somethingList)
{
     Type somethingType = foundSomething.GetType();
     Debug.WriteLine(
          string.Format("{0}\t{1}\t{2}"
               somethingType.Name, 
               somethingType.FullName,
               somethingType.Assembly.FullName),
               "TYPE-INFO");
}


The above generates the following information:

 

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