Dependency Injection Killed by Simon Ince

by Gael Fraiteur on 01 Jul 2008

Dependency Injection is Dead! is the somewhat provocative title of an interesting post of Simon Ince.

Simon indeed proposes another approach: AOP-powered Dependency Resolution. The idea is to use aspects on fields or properties to resolve the dependencies on-demand, when the property or field value is retrieved. Technically, it would be enough to turn the old good [Dependency] custom attribute into an aspect.

I won't copy-paste Simon's stuff, so please read from the horse's feather on his blog.

A refreshing view on a topic that tends to become sanctified and therefore unchallenged in our community.

Even if this approach does not solve all the use cases of Dependency Injection, covers a lot of them in quite an elegant way. While it would be theoretically easy to use this approach with dependency injection frameworks (because dependency resolution is obviously one the major components of a DI framework, the other big one being the object builder), I noticed that Unity does not offer the functionality at the required level of granularity. A pity, which I have notified in illo tempore to the Unity team. Maybe some day wind will turn...

Happy PostSharping!

-Gael