Circular-dependency best practice

对着背影说爱祢 提交于 2019-12-05 11:19:05

You can fix a circular reference by factoring out the things that both classes refer to into a new class, and then the old classes both refer to the new class.

So in your case you could move the entities out of DataAccess and into perhaps a new Entities namespace, used by both DataAccess and Application.

By doing this you start with

A <--> D

and end up with

A --> E
D --> E

Data Access Layer should not be in the same namespace as your domain objects. Entities should stand alone in an assembly/namespace that does not reference any other namespace, which will allow other logic based classes such as DataAccess and Parsers to reference the Entity on their own in a more clean manner.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!