Simple object creation with DIY-DI?
- by Runcible
I recently ran across this great article by Chad Perry entitled "DIY-DI" or "Do-It-Yourself Dependency Injection". I'm in a position where I'm not yet ready to use a IoC framework, but I want to head in that direction. It seems like DIY-DI is a good first step.
However, after reading the article, I'm still a little confused about object creation. Here's a simple example:
Using manual constructor dependency injection (not DIY-DI), this is how one must construct a Hotel object:
PowerGrid powerGrid; // only one in the entire application
WaterSupply waterSupply; // only one in the entire application
Staff staff;
Rooms rooms;
Hotel hotel(staff, rooms, powerGrid, waterSupply);
Creating all of these dependency objects makes it difficult to construct the Hotel object in isolation, which means that writing unit tests for Hotel will be difficult.
Does using DIY-DI make it easier?
What advantage does DIY-DI provide over manual constructor dependency injection?