Simple object creation with DIY-DI?
Posted
by Runcible
on Stack Overflow
See other posts from Stack Overflow
or by Runcible
Published on 2010-06-10T17:37:30Z
Indexed on
2010/06/10
17:42 UTC
Read the original article
Hit count: 376
dependency-injection
|diy
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?
© Stack Overflow or respective owner