- Prefer explicit binding over autowiring and letting the framework decide on which implementation to inject. Especially if you write modules that can be reused.
- Favor constructor injection over property injection: this way you get immutable classes and get the benefit of thread safety for free. The other benefit is that all your members will be initialised correctly and your object is created in a stable state.
- Avoid doing work in constructors, keep them as simple as possible and do initialisation in a separate init method that can throw exceptions if necessary.
- Write system tests that verify that all your dependencies are wired correctly.
- Avoid deep inheritance graphs. Always favor composition over inheritance (which is a principle of OO programming in general).
A lot of people had great expectations from this session on dependency injection. All seats were taken, all stairs were full, people even sat on the ground in the front. My curiousity kept me in the room for an hour, but the talk wasn't worth the sore back in the end.