我正在使用事件源在 CQRS 中构建用户登录和身份验证。(使用 AXON 框架)
以下是我的模型中的步骤 -
用户注册流程-
UserRegistrationCommand handles the user registration , since the application makes the uniqueness between users using email , means only one user can register with one email. (For this I was maintaining the table on read side , which contains the registered email address. So when user tries to register ,We query the read side for the validation of email address from client side (not from the write side),and show a message "This email is already register"). When the client validation passes ,the UserRegistrationCommand is issued and handled by the command handler , which then fires an event called UserRegistredEvent , and this event is handled by the event handler on read side and updates the read side DB.2. UserLogin Flow - 我对 UserLogin 有点困惑。
我有两种方法:
第一种方法 -
User login using the read side, means user enters the username and password. And this username and password is validated from read side, and UserLogedInEvent is fired from the read side and catched by the write side and is saved in event store.
但我从未在任何架构图中看到读取端触发和事件并由写入端处理。
那我可以这样做吗?
第二种方法 -
User login using write side , means the user issues UserLogingCommand
and before the command dispatch to command handler , we validate the
username and password using the read side by accessing the same public api
of read side (which was used in first approach).
但问题是,我们不能在写入端使用读取端(正如我在 cqrs 架构中阅读和了解的那样)。但由于我使用的是读取端的公共 API,所以我可以认为,它可能是正确的。
那么你们建议采用哪种方法,或者有其他方法可以做到这一点