After reading the nice answers in this question, I watched the screencasts by Justin Etheredge. It all seems very nice, with a minimum of setup you get DI right from your code.
Now the question that creeps up to me is: why would you want to use a DI framework that doesn’t use configuration files? Isn’t that the whole point of using a DI infrastructure so that you can alter the behaviour (the ‘strategy’, so to speak) after building/releasing/whatever the code?
Can anyone give me a good use case that validates using a non-configured DI like Ninject?
I don’t think you want a DI-framework without configuration. I think you want a DI-framework with the configuration you need.
I’ll take spring as an example. Back in the ‘old days’ we used to put everything in XML files to make everything configurable.
When switching to fully annotated regime you basically define which component roles yor application contains. So a given service may for instance have one implementation which is for ‘regular runtime’ where there is another implementation that belongs in the ‘Stubbed’ version of the application. Furthermore, when wiring for integration tests you may be using a third implementation.
When looking at the problem this way you quickly realize that most applications only contain a very limited set of component roles in the runtime – these are the things that actually cause different versions of a component to be used. And usually a given implementation of a component is always bound to this role; it is really the reason-of-existence of that implementation.
So if you let the ‘configuration’ simply specify which component roles you require, you can get away without much more configuration at all. Of course, there’s always going to be exceptions, but then you just handle the exceptions instead.