0

采取标准注册流程:

  1. 用户注册

  2. 用户收到带有链接激活帐户的电子邮件

  3. 用户激活帐户

我正在谈论的问题是:

  • 当我们创建初始帐户时,我们会存储用户名、密码、电子邮件、激活密钥

  • 当用户单击激活密钥链接时,我们使用 readmodel 验证密钥

  • 然后我们触发传递用户名的 ActivateAccountCommand

我如何加载用户帐户以在域中激活它?


最初我想将新用户 Acount.Id 传递给 readmodel 但在 CommandExecutorBase 中没有访问权限(我知道) - 我们不保存这个:

protected override void ExecuteInContext(IUnitOfWorkContext context,
       CreateAccountViaFormRegistrationCommand command)
{
    var newKey = Guid.NewGuid().ToString();
    var newAccount = new Account(
            command.UserName, command.Email, command.Password, newKey);
    SendWelcomeEmail(command.Email, command.UserName, newKey);
    context.Accept();
}  
4

1 回答 1

2

您可以发布一个AccountActivationKeySent事件,然后可以处理该事件以在读取端填充您需要的任何投影。类似于以下内容:

// 1. Create and send the command from your client:

var command = new CreateAccountViaFormRegistrationCommand {
    AccountId = Guid.NewGuid(),
    ...
}

// 2. Create a new account in your command handler

var newAccount = new Account(command.AccountId, ...);
context.Accept();

// 3. And your account constructor (assuming it's inheriting from one
//    of EventSource's subclasses, e.g. AggregateRootMappedByConvention) 
//    might look like this:

public Account(Guid accountId, string name, ...) {
  EventSourceId = accountId;
  ApplyEvent(new AccountCreated { AccountId = Id, ... } );
  ApplyEvent(new AccountActivationSent { AccountId = Id, ... })
}
于 2011-11-16T14:21:24.083 回答