Tuesday, November 4, 2008

Dependency Injection Myth: Reference Passing

Miško Hevery (blog via Dave Dribin):

Since UserRepository can no longer do a global look-up to get a hold of the Database it musk ask for it in the constructor. Since LoginPage is doing the construction it now needs to ask for the Databse so that it can pass it to the constructor of the UserRepository. The myth we are describing here says that this makes code hard to understand and maintain. Guess what?! The myth is correct! The code as it stands now is hard to maintain and understand. Does that mean that dependency injection is wrong? NO! it means that you only did half of the work!

Comments RSS · Twitter

Leave a Comment