Lately I find myself not caring too much defining dependencies for a class and passing them in the constructor, but I just always pass the DI container and keep it in a private attribute. This way my class won't have very well-defined dependencies, I get everything from the container when I need it.
Somehow I have bad feelings about this solution though (apart from the overhead caused by accessing the container), but I can't really think of too much disadvantages. Maybe having loose definition of dependencies can decrease portability of a class, or I get surprises when refactoring...?
What do you think about this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…