Iterate registered types?

May 7, 2009 at 2:36 PM
Hi,

Im using the unity container as part of the WPF composite application guidance.

I have modules that register a number of types of classes with the same interface.

eg CustomerModule.dll
container_.RegisterType<ICustomer, InternalCustomer>( "InternalCustomer")
container_.RegisterType<ICustomer, ExternalCustomer>("ExternalCustomer")
container_.RegisterType<ICustomer, HappyCustomer>("HappyCustomer")
container_.RegisterType<ICustomer, SadCustomer>("SadCustomer")

This allows me to later create an instance of a type by just specifying the type name to the container eg:

var cust  = container_.Resolve<ICustomer>("ExternalCustomer")

I want my main shell application to display a list of all the available ICustomer types in the container. However, it appears the closest I can come is calling:
 
var lst = container_.ResolveAll<ICustomer>();

which means I need to actually instantiate all those objects in order to see which are in the container.

What Im really looking for is a method like container_.FindTypes<ICustomer> or something that can just return all the types for a particular interface.

any ideas?

thanks,
Adam
Dec 17, 2009 at 10:38 PM

This has been implemented in Unity 2.0. See the latest drop.