简体   繁体   English

所有内部程序集与具有外部依赖项的程序集

[英]All internal assemblies vs. assemblies that have external dependencies

If I have two assemblies, one containing just business rules (assembly A), and the other that acts as an interface to external dependencies such as File system, DBs, web services, etc. (assembly B), should A reference B or should B reference A? 如果我有两个程序集,一个仅包含业务规则(程序集A),另一个则充当外部依赖项(如文件系统,DB,Web服务等)的接口(程序集B),则应引用A还是应引用B。 B参考A?

For Example: 例如:

If I have a SourceCodeInterpreter class (assembly A), should it instantiate a SourceCodeFileReader (in assembly B) to read in the data, or should the SourceCodeFileReader instantiate a SourceCodeInterpreter class after reading the source file and then start the interpreter? 如果我有SourceCodeInterpreter类(程序集A),它应该实例化SourceCodeFileReader(在程序集B中)以读取数据,还是应该SourceCodeFileReader在读取源文件后实例化SourceCodeInterpreter类,然后启动解释器?

It all depends on how things are going to be used. 这完全取决于如何使用事物。 If an assembly uses a type defined in another assembly, it will need a reference to it. 如果程序集使用在另一个程序集中定义的类型,则需要对其进行引用。 I try to avoid adding dependencies between assemblies unless they really have a reason for existing. 我尽量避免在程序集之间添加依赖项,除非它们确实有存在的理由。

In your example, I'd try to leave the two assemblies separate. 在您的示例中,我尝试将两个程序集分开。 Both of these assemblies are most likely being used by your application. 您的应用程序很可能会同时使用这两个程序集。 Your application can reference both, and they can be independant. 您的应用程序可以引用这两者,并且它们可以是独立的。 The app would use SourceCodeFileReader to read in your code, then pass it to your SourceCodeInterpreter to interpret it. 该应用程序将使用SourceCodeFileReader读取代码,然后将其传递给SourceCodeInterpreter进行解释。

If, however, you're trying to make this require a single type to be used, I'd put the "top level" assembly as the one containing a reference to the "lower level details". 但是,如果您要使它只需要使用一种类型,我将把“顶层”程序集作为包含对“底层细节”的引用的程序集。 In this case, that would probably mean having the interpreter reference the reader - since a reader is lower level, and useless on its own. 在这种情况下,这可能意味着让解释器引用读者-因为读者是较低级别的,并且本身没有用处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM