Unity 2.0 will have an IsRegistered method, which you can use to find out if a type is registered in the container.
Unity 2.0 beta 1 has been available on Codeplex since February 10th. See Release Notes and download it here; http://unity.codeplex.com/wikipage?title=Unity2%20Beta1
UPDATE:
We downloaded and tested Unity 2.0 beta 1 on February 27, 2010, and it is now ready for release. If you are using Unity 1.2 today, you will need to do some important work to get Unity 2.0 to work due to the incomplete (?) IUnityContainer interface. Therefore, if you want the IsRegistered method to work today, you can make such an extension method as follows:
public static class UnityContainerExtensions { public static bool IsRegistered<T>(this IUnityContainer container) { try { container.Resolve<T>(); return true; } catch { return false; } } }
Please note that I am not using ResolveAll here. The reason for this is that ResolveAll will not return the standard (unnamed) registration as specified in the Unity docs:
This method is useful if you have registered several types with the same type, but with different names.
Remember that this method does NOT return an instance for standard (unnamed) registration.
Kjetil klaussen
source share