Not long ago, Jeremy Miller released version 1.0 his excellent dependency injection tool, StructureMap. I’ve ported it to .Net 2.0, and I’ve added generics to the bread and butter class, ObjectFactory. Download the .Net 2.0 release on sourceforge.net. StructureMap supports creating very loosely coupled applications by service location and dependency injection.
Coding to interfaces is fine and dandy, but at some point, you need an instance of the concrete class that implements the interface. Typing “new SomeClass” tightly couples your code, so what do you do?
Slap an attribute on the interface, the concrete class, and then all you have to type is:
IMyInterface instance = ObjectFactory.GetInstance<IMyInterface>( );
That’s all it takes, and you have an instance of the interface you are binding against. Using this pattern, you can harvest reuse in your applications and test any component in isolation.