Can dependency injection prevent a circular dependency?

后端 未结 3 496
无人及你
无人及你 2020-12-06 04:01

Project#1 has some interfaces and classes that project#2 references.

Now I want to use the implementation of Project#2 in Project#1 but vs.net complains about a circ

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 04:12

    As long as you are only using classes and interfaces from Project 1 in Project 1 code, you will be fine. (I'm assuming that the configuration for the dependency injection is done outside of the codebase of Project 1.)

    But I have to also say, the presence of any circular dependency should lead you to question why it exists, and prompt thought on other ways to solve the problem that removes it.

提交回复
热议问题