Container Configuration
I’ve grown to like IoC containers. It’s no surprise. The concept does indeed kick ass. (I won’t explain what they are or what they do. No need to reiterate the discussions of 3 years ago, or that article from Martin Fowler I’ve linked two lines ago.)
I also like concept of autowiring or autoconfiguration based on convention. I LOVE the fact that you can let StructureMap do all my dirty work like this:
public void BootstrapStructureMap()
{
ObjectFactory.Initialize(
x => x.Scan(
y =>
{
y.TheCallingAssembly();
y.WithDefaultConventions();
}));
}
Yes, that’s ALL the configuration I have centralized. (marking singleton behavior is something I prefer to do on the type itself, and not in a central configuration)
The best part about this whole thing is that unlike most “right” things we do in software – this actually saves you time on the long term, short term, AND the immediate term. You write less code to create a more sustainable application. Who can say no to that?
And let’s be clear about it – I know very little about how to use SM, but the little I know – works great. I use construction dependencies injection almost exclusively, and no other fancy injection (like property injection. Real fancy, ah?) methods, and let the container slide everything around.
This could cause some problems, in case you have created some circular dependency between your components (ctor of type A needs an instance of B, which in turn needs an instance of type A). I often find this out when I run a some test and TestDriven crashes because of a stack overflow. Fun. :)