问题描述
如果我有这两个项目:
MyCompany.ERP.Billing
MyCompany.ERP.Financial
结算问/将信息发送到金融,反之亦然。两者都太大了,所以我不想把它们放在一个单一的项目。Visual Studio中不允许循环引用。你会如何处理呢?
Billing asks/sends information to Financial and vice-versa. Both are too big so I don't want to put them in a single project.Visual Studio doesn't allow circular references. How would you deal with that?
推荐答案
从你的类中提取接口,并把它们放到两个结算
从引用的一个核心项目,金融
项目。然后,您可以使用这些接口组件之间共享数据。
Extract interfaces from your classes and put them into a core project referenced from both Billing
and Financial
projects. You can then use those interfaces to share data between assemblies.
这不仅可以让你的通过 2的那些组件之间的对象,但不能创建从其他对象,因为你实际上并没有一个参考的开始。如果您希望能够创建你需要一个工厂,外部对这些2个项目的对象,处理对象的创建。
This only allows you to pass objects between those 2 assemblies, but you can't create objects from the other since you don't actually have a reference to begin with. If you want to be able to create objects you need a factory, external to those 2 projects, that handles object creation.
我会抽取需要共享数据来回结算
和金融
之间到另一个业务逻辑项目。这将使事情变得更简单,并会为您节省诉诸于所有种类的技巧,使维护的噩梦。
I would extract the business logic that needs to share the data back and forth between Billing
and Financial
into another project. This would make things a lot easier and would save you from resorting to all sort of tricks that make maintainability a nightmare.
这篇关于如何处理循环引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!