Find current container

Apr 14, 2008 at 1:31 AM
Is there a way to find out what the current container is? I am thinking about something like:

IDesiredService service = UnityContainer.Current.Resolve<IDesiredService>();

This allows me to have a class that can get to a service without having to be passed an instance of the container.

Thanks,
Rob Cannon

Apr 14, 2008 at 4:00 AM
Unity doesn't have a concept of a "current container". If you want one, it's easy enough to have a static variable somewhere holding that current instance.

Be aware that by doing this, you're coupling your class to the container, which defeats the point of using a DI container in the first place.