tags:

views:

287

answers:

1

I've got a Prism project with code that I've gotten from various sources, everything is working quite nicely, but I noticed that in some modules I inject

IContainer container

and in other modules I inject

IUnityContainer container

IContainer only seems to have Components, Add, and Remove while IUnityContainer has dozens of methods.

I'm changing IContainer to IUnityContainer often so that I can use the latter's resolve methods. What is the difference between these two and why would I want to use IContainer?

+2  A: 

These are really two different things with different purposes.

The IUnityContainer is a dependency injection container that supports all of the things you'd need to do in a dependency injection / service location scenario, like BuildUp, Resolve, Register, etc. You can read more about Unity (which is actually part of Enterprise Library and used by the CAG) by going here: Unity on Codeplex

IContainer is used to create a generic container for objects that are IComponents. It's used by a number of components and is in the .NET Framework in System.ComponentModel. It is not related to Unity or the CAG in any direct way. I would consider this to be something that was more Windows Forms specific and less WPF, although you can use IComponents in WPF indirectly. IContainer

When doing any kind of dependency injection, you should be using IUnityContainer, not IContainer.

Anderson Imes