Dependency Injection “nesting” in related methods

前端 未结 2 1196
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 10:25

We\'re using DI and Unity to work with different dependencies (generally, database and repository classes, dto to entity mappers, etc) Right now we\'re trying to create smaller

相关标签:
2条回答
  • 2021-01-26 11:05

    The approach we use is constructor injection, then we store the dependency in a private member field. The container wires up the dependencies; so the number of classes and constructor parameters doesn't really matter.

    This works for services. If the dependencies across calls have meaningful state, you will have to pass them in to each call. But, in that case, I'd question if the methods really need to be public methods in their own classes.

    You want to end up with a design that eliminates the service locator and truly injects the dependencies.

    0 讨论(0)
  • 2021-01-26 11:16

    Does the null object pattern help?

    http://en.wikipedia.org/wiki/Null_Object_pattern

    0 讨论(0)
提交回复
热议问题