简体   繁体   English

洋葱架构:核心与域名

[英]Onion Architecture: Core vs Domain

I study Onion Architecture for quite sometime now, I've analysed few sample VS's solutions and still can't understand the difference between Core and Domain in Onion Architecture . 我现在研究Onion Architecture很长一段时间了,我已经分析了几个VS的解决方案,但仍然无法理解Onion Architecture CoreDomain之间的区别。

  • In this solution Core (project) is inside Domain (solution folder). 解决方案中,Core(项目)位于Domain(解决方案文件夹)中。
  • Here there is no Core, only Domain 这里没有Core,只有Domain
  • In Jeffrey Palermo's CodeCampServer sample app, there is Domain inside Core. 在Jeffrey Palermo的CodeCampServer示例应用程序中,Core内部有Domain。 So, basically it looks like Core is made of Domain and Services . 因此,基本上看起来Core是由DomainServices
  • In this xDriven project Core is divided into Core.Application and Core.Domain 这个xDriven项目中, Core分为Core.ApplicationCore.Domain

I'm totally confused. 我完全糊涂了。 Can you explain me, what's the actual difference between Core and Domain in such architecture? 你能解释一下, CoreDomain在这种架构中的实际区别是什么?

I have for example this class. 我有这样的课程。 Simple board game, like tic-tac-toe. 简单的棋盘游戏,如井字游戏。 It's definitely ubiquitous language, so should I create it in Entities folder inside Domain? 它绝对是无处不在的语言,所以我应该在Domain内的Entities文件夹中创建吗? And domain itself in Core? Core中的域名本身?

public class Game
{
    public GameState State { get; set; }
    public Board Board { get; set; }
    public IEnumerable<Player> Players { get; set; }

    public bool Move(int playerId, int field)
    {
        //Check if Player's move will finish game. If yes, return true
        return false;
    }
}

In my opinion, as long as you follow guidelines from Onion Architecture the actual naming of projects is not that important. 在我看来,只要你遵循Onion Architecture的指导方针,项目的实际命名就不那么重要了。 It's more about structuring your project to easily work with it and reason about it. 它更多的是关于构建项目以便轻松使用它并推理它。

It's important to have independent object model that is in center. 拥有独立的对象模型非常重要。 And you build your application around that model. 然后围绕该模型构建应用程序。

I'm totally confused. 我完全糊涂了。 Can you explain me, what's the actual difference between Core and Domain in such architecture? 你能解释一下,Core和Domain在这种架构中的实际区别是什么?

You can think about Core as a aggregation of every aspect of you architecture center model that should be independent. 您可以将Core视为您应该是独立的架构中心模型的每个方面的集合。 In that Post about Onion Architecture there is Application Core and it contains Domain Model , Domain Services and Application Services . 关于洋葱架构的帖子中,Application Core ,它包含Domain ModelDomain ServicesApplication Services It depends on your project what you have in Core . 这取决于您的项目您在Core拥有的内容。 Maybe in your case there is no need to introduce Application Services . 也许在您的情况下,没有必要引入Application Services

So to wrap up, structure your solution that it is easy for you and others to reason about. 总而言之,构建您的解决方案,让您和其他人轻松推理。 Let the structure in your solution be guideline for others working with that project. 让解决方案中的结构成为使用该项目的其他人的指南。 By that I mean, if someone must implement new feature in project, the solution should guides him where he should put for example Domain Entities and etc. And my last thought, the most important thing than structuring (naming) projects is to keep focus on adhering to four tenets of Onion Architecture as described here 我的意思是,如果有人必须在项目中实现新功能,那么解决方案应该指导他应该放置Domain Entities等等。而我最后的想法,比构建(命名)项目最重要的是继续关注遵循这里描述Onion Architecture四个原则

To add up to Arkadiusz K's point that Core is an overloaded term, in DDD speech Core Domain can also be used as opposed to (Supporting/Generic) Subdomain. 为了加起来Arkadiusz K的观点,Core是一个重载项,在DDD语音中,Core Domain也可以用作(支持/通用)子域。 That is, you have one or a few crucial domains that are your core business and other domains that are ancillary and could be outsourced or bought as off-the-shelf solutions. 也就是说,您有一个或几个关键域是您的核心业务和其他辅助域,可以外包或作为现成的解决方案购买。

Domains and subdomains correspondence in the solution space is Bounded Contexts, and these can be expressed as namespaces in code. 解空间中的域和子域对应是有界上下文,这些可以在代码中表示为名称空间。 That might have been what the authors of some of the examples had in mind. 这可能是一些例子的作者想到的。

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

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