Domain driven design 以数据为中心的流程中的CQR
我有一个关于以数据为中心的流程中CQR的问题。让我解释清楚。 考虑到我们有一个SOAP/JSON/任何服务,它在集成过程中将一些数据传送给我们的系统。据说,在CQR中,如果使用事件源,则必须通过命令或事件实现每个状态更改 当涉及到我们的集成过程时,我们得到了大量结构化数据,而不是一组命令/事件,我想知道如何实际处理这些数据Domain driven design 以数据为中心的流程中的CQR,domain-driven-design,integration,cqrs,Domain Driven Design,Integration,Cqrs,我有一个关于以数据为中心的流程中CQR的问题。让我解释清楚。 考虑到我们有一个SOAP/JSON/任何服务,它在集成过程中将一些数据传送给我们的系统。据说,在CQR中,如果使用事件源,则必须通过命令或事件实现每个状态更改 当涉及到我们的集成过程时,我们得到了大量结构化数据,而不是一组命令/事件,我想知道如何实际处理这些数据 // Some Façade service class SomeService { $_someService; public function __co
// Some Façade service
class SomeService
{
$_someService;
public function __construct(SomeService $someService)
{
$this->_someService = $someService;
}
// Magic function to make it all good and
public function process($dto)
{
// if I get it correctly here I need somehow
// convert incoming dto (xml/json/array/etc)
// to a set of commands, i. e
$this->someService->doSomeStuff($dto->someStuffData);
// SomeStuffChangedEvent raised here
$this->someService->doSomeMoreStuff($dtom->someMoreStuffData);
// SomeMoreStuffChangedEvent raised here
}
}
我的问题是,我的建议是否适合特定情况,或者是否有更好的方法来满足我的需要。提前谢谢。同意,服务可能有不同的接口。如果您创建一个RESTAPI来更新员工,您可能希望提供一个UpdateEmployeeMessage,其中包含所有可以更改的内容。在CRUD类型的服务中,此消息可能会镜像数据库 在服务内部,您可以将消息拆分为以下命令:
public void Update(UpdateEmployeeMessage message)
{
bus.Send(new UpdateName
{
EmployeeId = message.EmployeeId,
First = message.FirstName,
Last = message.LastName,
});
bus.Send(new UpdateAddress
{
EmployeeId = message.EmployeeId,
Street = message.Street,
ZipCode = message.ZipCode,
City = message.City
});
bus.Send(new UpdateContactInfo
{
EmployeeId = message.EmployeeId,
Phone = message.Phone,
Email = message.Email
});
}
或者您可以直接调用聚合:
public void Update(UpdateEmployeeMessage message)
{
var employee = repository.Get<Employee>(message.EmployeeId);
employee.UpdateName(message.FirstName, message.LastName);
employee.UpdateAddress(message.Street, message.ZipCode, message.City);
employee.UpdatePhone(message.Phone);
employee.UpdateEmail(message.Email);
repository.Save(employee);
}
看起来不错,不过这取决于你的需要。您在对您的应用程序服务进行这两次调用时是否遇到任何问题?