I have been using StructureMap for over a year now. And all this time I had a wrapper class called IoC, which looked like this:
class IoC {
public static T GetInstance<T>()
{
return (T)GetInstance(typeof(T));
}
public static IEnumerable<T> GetAllInstances<T>()
{
return ObjectFactory.GetAllInstances<T>();
}
public static IEnumerable GetAllInstances(Type type)
{
return ObjectFactory.GetAllInstances(type);
}
public static object GetInstance(Type type)
{
return ObjectFactory.GetInstance(type);
}
public static void Inject<T>(T obj)
{
ObjectFactory.Inject(obj);
}
}
I added a wrapper, suggesting that I might need to change the IoC container at some point in the line. At the moment, I think this is bad. One of the reasons: I cannot use ObjectFactory in my code to do other interesting things, I have to use this shell. Another thing: our code should not be really independent of the DependencyInjection container.
What are the advantages / disadvantages of using this approach?
source
share