In my opinion the number one benefit of an IoC is the ability to centralize the configuration of your dependencies.
If you're currently using Dependency injection your code might look like this
public class CustomerPresenter
{
public CustomerPresenter() : this(new CustomerView(), new CustomerService())
{}
public CustomerPresenter(ICustomerView view, ICustomerService service)
{
// init view/service fields
}
// readonly view/service fields
}
If you used a static IoC class, as opposed to the, IMHO the more confusing, configuration files, you could have something like this:
public class CustomerPresenter
{
public CustomerPresenter() : this(IoC.Resolve(), IoC.Resolve())
{}
public CustomerPresenter(ICustomerView view, ICustomerService service)
{
// init view/service fields
}
// readonly view/service fields
}
Then, your Static IoC class would look like this, I'm using Unity here.
public static IoC
{
private static readonly IUnityContainer _container;
static IoC()
{
InitializeIoC();
}
static void InitializeIoC()
{
_container = new UnityContainer();
_container.RegisterType();
_container.RegisterType();
// all other RegisterTypes and RegisterInstances can go here in one file.
// one place to change dependencies is good.
}
}