事件溯源聚合根用户
我是事件采购领域的新手,我启动了一个新项目来了解它,但我有几个关于架构的问题。
我的第一个问题是关于聚合根的。我有一个UserAggregateRoot
。该聚合是否应包含用户实体通常可识别的属性?
我的意思是我的Aggregate
看起来像这样
public class UserAggregateRoot : AggregateRoot
{
public Login Login { get; private set; }
public Password Password { get; private set; }
public Name Name { get; private set; }
public DateTime BirthDate { get; private set; }
public UserId UserId { get; private set; }
public Status Status { get; private set; }
private void Apply(UserCreatedEvent e)
{
Version = e.Version;
Login = e.Login;
Password = e.Password;
Name = e.Name;
BirthDate = e.BirthDate;
Key = e.Key;
}
private void Apply(UserActivatedEvent e)
{
Version = e.Version++;
Status = e.Status;
Key = e.Key;
}
private void Apply(UserDeletedEvent e)
{
Version = e.Version++;
Key = e.Key;
}
private void Apply(UserLogedEvent e)
{
Version = e.Version++;
Key = e.Key;
}
private void Apply(UserUpdatedEvent e)
{
Version = e.Version++;
Login = e.Login;
Password = e.Password;
Name = e.Name;
Key = e.Key;
}
}
或者也许UserAggregateRoot
应该存储用户实体看起来像
public class UserAggregateRoot : AggregateRoot
{
public User User { get; private set; }
private void Apply(UserCreatedEvent e)
{
User = e.User;
Key = e.User.Key;
}
private void Apply(UserActivatedEvent e)
{
Version = e.Version++;
User = e.User;
Key = e.User.Key;
}
private void Apply(UserDeletedEvent e)
{
Version = e.Version++;
Key = e.User.Key;
User = e.User;
}
private void Apply(UserLogedEvent e)
{
Version = e.Version++;
Key = e.User.Key;
}
private void Apply(UserUpdatedEvent e)
{
Version = e.Version++;
User = e.User;
Key = e.User.Key;
}
}
第二个问题是如果UserAggregateRoot
存储一些订单,我应该存储UserAggregateRoot
中的订单实体列表?
如果订单是类似于 OrderAggregateRoot
的 AggregateRoot
该怎么办?我应该将 AggregateKey
存储在我的 UserAggregateRoot
中以指向此 OrderAggregateRoot
吗?
第三个问题是聚合根是否应该在内部包含业务逻辑,或者业务逻辑是否应该在传递给此聚合的实体内部以及内部值对象?
I'm new in event sourcing, and I started a new project to learn about it but I have a couple of questions about architecture.
My first question is about aggregate root. I have a UserAggregateRoot
. Did this aggregate should contain properties that are typically recognizable to user entities?
I mean my Aggregate
looks like that
public class UserAggregateRoot : AggregateRoot
{
public Login Login { get; private set; }
public Password Password { get; private set; }
public Name Name { get; private set; }
public DateTime BirthDate { get; private set; }
public UserId UserId { get; private set; }
public Status Status { get; private set; }
private void Apply(UserCreatedEvent e)
{
Version = e.Version;
Login = e.Login;
Password = e.Password;
Name = e.Name;
BirthDate = e.BirthDate;
Key = e.Key;
}
private void Apply(UserActivatedEvent e)
{
Version = e.Version++;
Status = e.Status;
Key = e.Key;
}
private void Apply(UserDeletedEvent e)
{
Version = e.Version++;
Key = e.Key;
}
private void Apply(UserLogedEvent e)
{
Version = e.Version++;
Key = e.Key;
}
private void Apply(UserUpdatedEvent e)
{
Version = e.Version++;
Login = e.Login;
Password = e.Password;
Name = e.Name;
Key = e.Key;
}
}
Or maybe UserAggregateRoot
should store user entity looks likes that
public class UserAggregateRoot : AggregateRoot
{
public User User { get; private set; }
private void Apply(UserCreatedEvent e)
{
User = e.User;
Key = e.User.Key;
}
private void Apply(UserActivatedEvent e)
{
Version = e.Version++;
User = e.User;
Key = e.User.Key;
}
private void Apply(UserDeletedEvent e)
{
Version = e.Version++;
Key = e.User.Key;
User = e.User;
}
private void Apply(UserLogedEvent e)
{
Version = e.Version++;
Key = e.User.Key;
}
private void Apply(UserUpdatedEvent e)
{
Version = e.Version++;
User = e.User;
Key = e.User.Key;
}
}
Second question is if UserAggregateRoot
stores some orders, should I store the order entity list inside this UserAggregateRoot
?
What if orders are AggregateRoot
something like OrderAggregateRoot
? Should I store AggregateKey
inside my UserAggregateRoot
to point this OrderAggregateRoot
?
Third question is should Aggregate
root have business logic inside or should business logic be inside entity passed to this Aggregate
and inside value objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OrderAggregateRoot
,其属性包含UserAggregateRoot
的AggregateKey
。OrderAggregateRoot
甚至可能是完全不同的有界上下文。如果您想了解有关定义聚合根的更多详细信息,我建议您寻找定义事务边界。OrderAggregateRoot
with a property that contains theAggregateKey
of theUserAggregateRoot
.OrderAggregateRoot
might even be an entirely different bounded context. If you want more details on defining aggregate roots I suggest looking for defining transactional boundaries.