【发布时间】:2015-03-26 13:13:06
【问题描述】:
我有一个 CreateUserCommand 负责创建帐户。
public class UserCommandHandler : ICommandHandler<CreateUserCommand>
{
private readonly IUserRepository repository;
public UserCommandHandler(IUserRepository repository)
{
this.repository = repository;
}
public void Handle(CreateUserCommand command)
{
User user = new User();
user.Username = command.Username;
user.Password = command.Password;
user.Email = command.Email;
repository.Add(user);
repository.Save();
}
}
但我有包含 (UserId, RoleID) 列的 UserInRoles 表。所以我必须在创建后将用户添加到角色中。
如何使用 CQRS 进行这种嵌套操作?
【问题讨论】:
-
所以你们都有一个 Users 和一个 UserInRoles 表,而不仅仅是上面代码中缺少的 RoleId 值,对吗?
标签: design-patterns domain-driven-design cqrs