域驱动设计中跨有限上下文的实体 [英] Entities across bounded contexts in Domain-Driven Design

查看:92
本文介绍了域驱动设计中跨有限上下文的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解实体在多个有界上下文中的运作方式。

I am trying to understand how entities operate in multiple bounded contexts.

给定公司的雇员。在(例如)人力资源上下文中,此人具有姓名,姓氏,地址,薪水参考编号和银行帐户。但是在会计方面,所有相关的只是薪水参考编号和银行帐户。

Given an Employee of a Company. In (for example) the Human Resources context, this person has a name, surname, address, salary reference number, and bank account. But in the Accounting context all that is relevant is the salary reference number and bank account.

您在HR上下文中是否有一个Employee实体和一个Value-Type(例如, SalariedEmployee )在会计上下文中?

Do you have an Employee entity in the HR context and a Value-Type (e.g. SalariedEmployee) in the Accounting context?

class Employee
{
    public BankAccount BankAcountDetails { get; set; }
    public string FullName { get; set; }
    public Address ResidentialAddress { get; set; }
    public string SalaryRef { get; set; }
}

SalariedEmployee 类(??):员工的值类型

SalariedEmployee class (??) : Employee's value-type

class SalariedEmployee
{
    public SalariedEmployee(string salaryRef, BankAccount bankAcountDetails)
    {
        ...
    }

    public string SalaryRef { get; }
    public BankAccount BankAcountDetails { get; }
}

边界环境中的HRService是否返回此信息?还是在两种情况下都使用Employee类?

Does the HRService in the bounded context return this information? Or do you use the Employee class in both contexts?

推荐答案

来自 http://msdn.microsoft.com/zh-CN/library/jj554200.aspx

有界上下文是自治的组件,具有自己的域模型和自己的通用语言。它们在运行时彼此之间不应有任何依赖关系,并且应该能够独立运行。但是它们是同一整体系统的一部分,并且确实需要彼此交换数据。

Bounded contexts are autonomous components, with their own domain models and their own ubiquitous language. They should not have any dependencies on each other at run time and should be capable of running in isolation.However they are a part of the same overall system and do need to exchange data with one another.

如果要实现 CQRS模式 ,在有界的上下文中,您应该使用事件进行此类通信:有界的上下文可以响应在有界的上下文之外引发的事件,有界的上下文可以发布其他有界的上下文可能订阅的事件。事件(发布有关已发生事件的信息的单向异步消息)使您能够维护有限上下文之间的松散耦合。

If you are implementing the CQRS pattern in a bounded context, you should use events for this type of communication: your bounded context can respond to events that are raised outside of the bounded context, and your bounded context can publish events that other bounded contexts may subscribe to. Events (one-way, asynchronous messages that publish information about something that has already happened), enable you to maintain the loose coupling between your bounded contexts.

这篇关于域驱动设计中跨有限上下文的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆