首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NCQRS:如何从域加载?

NCQRS:如何从域加载?
EN

Stack Overflow用户
提问于 2011-11-15 21:57:43
回答 1查看 248关注 0票数 0

采用标准登记程序:

  1. 用户注册
  2. 用户发送电子邮件与链接激活帐户
  3. 用户激活帐户

我说的问题是:

  • 在创建初始帐户时,我们存储用户名、密码、电子邮件、激活密钥
  • ,当用户单击激活键链接时,我们使用readmodel
  • 验证密钥,然后启动传入用户名

的ActivateAccountCommand。

如何加载用户帐户以激活域中的用户帐户?

最初,我希望将新用户Acount.Id传递给readmodel,但在CommandExecutorBase中没有访问(据我所知)--我们不保存以下内容:

代码语言:javascript
复制
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();
}  
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-16 14:21:24

您可以发布一个AccountActivationKeySent事件,然后可以处理该事件,以填充读取端所需的任何投影。与…有关的东西:

代码语言:javascript
复制
// 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, ... })
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8143729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档