简体   繁体   English

域驱动设计(DDD),我的域可以引用RabbitMQ或任何其他nuget包吗?

[英]Domain Driven Design (DDD), can my domain have a reference to a RabbitMQ or to any other nuget package?

I am new at DDD and I came up with a question about a implementation that I recently made. 我是DDD的新手,我提出了一个关于我最近做的实现的问题。 The User layer of my DDD project asks the application Layer for a IModel type object for connecting to a RabbitMq Brooker. 我的DDD项目的User层要求应用层提供一个用于连接RabbitMq Brooker的IModel类型对象。 Then the application layer asks a domain layer service for a IModel, that finally delegates to the Infra Layer that task (through Interface implementation). 然后,应用层向域层服务请求IModel,最终委托给Infra Layer该任务(通过Interface实现)。 It works fine, but the question is: is it against the DDD principle the Domain layer have knowledge of another project? 它运行正常,但问题是:它是否违反DDD原则,Domain层有另一个项目的知识? Even though it is a Nuget package project. 即使它是Nuget包项目。

Yes. 是。 Domain layer should be the very center of your architecture and it cares just about domain rules and invariants. 域层应该是您的架构的核心,它只关心域规则和不变量。 All the coordination and plumbing should go into Application layer. 所有的协调和管道都应该进入Application层。

A good start is Onion Architecture or Hexagonal Architecture 洋葱建筑六角建筑是一个良好的开端

Also check this DDD Decoded post (it worth taking a look at the complete DDD Decodes serie) to see a implementation about how use the application layer to coordinate the business with all other things. 还要检查这个DDD解码后的帖子(值得看一下完整的DDD Decodes系列),看一下如何使用应用层来协调业务与其他所有事情的实现。

Note you are asking two different questions. 请注意,您提出两个不同的问题。

Domain Driven Design (DDD), can my domain have a reference to a RabbitMQ or to any other nuget package? 域驱动设计(DDD),我的域可以引用RabbitMQ或任何其他nuget包吗?

NO 没有

is it against the DDD principle the Domain layer have knowledge of another project? 是否违反DDD原则,Domain层有另一个项目的知识?

YES

The domain should have the fewest dependencies possible. 域应该具有最少的依赖性。 So your domain layer should not have NuGet packages in it (in General). 因此,您的域层不应包含NuGet包(一般情况下)。

now your domain layer can have an interface that you know will most likely be filled in the application layer by a provider. 现在,您的域层可以拥有一个接口,您知道该接口最有可能由提供商填充在应用层中。 but this interface should be your interface , not an interface provided via a third party. 但是这个界面应该是你的界面 ,而不是通过第三方提供的界面。

If you know you are to use a third party object later in the application. 如果您知道以后要在应用程序中使用第三方对象。 I think pure DDD would have you write your own interface then use the adaptor pattern to convert third party implementation to work with your interface. 我认为纯DDD会让你编写自己的界面然后使用适配器模式转换第三方实现以使用你的界面。

So, in this case, your Domain level does not have any outside dependencies or knowledge of what is in the application layer. 因此,在这种情况下,您的域级别没有任何外部依赖关系或知道应用程序层中的内容。

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

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