Using Dependency Injection frameworks for classes with many dependencies

后端 未结 6 412
无人及你
无人及你 2021-01-30 07:21

I have been looking at various dependency injection frameworks for .NET as I feel the project I am working on would greatly benefit from it. While I think I have a good grasp of

6条回答
  •  别那么骄傲
    2021-01-30 07:55

    First:

    You could inject these objects, when needed, as members instead of in the constructor. That way you don't have to make changes to the constructor as your usage changes, and you also don't need to use a static.

    Second:

    Pass in some sort of builder or factory.

    Third:

    Any class should only have those dependencies that it itself requires. Subclasses should be injected with their own specific dependencies.

提交回复
热议问题