采取标准注册流程:
用户注册
向用户发送带有链接激活帐户的电子邮件
用户激活帐户
当我们创建初始帐户时,我们会存储用户名,密码,电子邮件,激活密钥
当用户点击激活密钥链接时,我们使用readmodel验证密钥
然后我们触发传递用户名
如何加载用户帐户以在域中激活它?
最初我想将新用户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();
}
答案 0 :(得分: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, ... })
}