Recently I have been trying to implement CQRS + DDD in my new ASP.NET Core project, as CQRS and DDD are very new to me, I read a lot of articles and examples online but could not get a deeper understanding.
Generic example:
I have the following:
Structure:
Front-End <==> Controller <==> Mediatr <==> Command Handler <==> Repository
Or
Front-End <==> Controller <==> Mediatr <==> Query Handler <==> Reader
I use Mediatr library to handle all my commands and queries.
Repository returns/save Aggregate Root/Domain/WriteModel, Reader returns ReadModel.
Aggregate Root/Domain/WriteModel: class User { string UserId , string Password }
Command: CreateUserCommand which takes in new user's UserId and Password and create a new User, then save it with Repository. Publish a UserCreatedEvent.
Now I want to create a function for clients to authenticate with UserId and Password. The function should have UserId and Password as input, and I will return UserAuthResult which has a bool field, true if UserId and Password is valid
I am thinking to create a AuthenticateUserQuery but I am not sure if it is actually a valid Query, or just a Domain Service.
The code flow of AuthenticateUserQuery would probably be:
ControllersendAuthenticateUserQuerytoMediatrMediatrexecuteAuthenticateUserQueryHandler.Handle()AuthenticateUserQueryHandlergetUserAuthDetailReadModelfromUserAuthDetailReader- Do authenticate with query's
UserId+PasswordandUserAuthDetailReadModel - Return
UserAuthResult
Questions Time!
- From the description above,
AuthenticateUserQueryonly performs query/read, is it a validQueryorDomain Service - If Question #1 is
Query, isUserAuthResultaReadModel? (Since it is returned from aQuery) - If Question #2 is a YES, is
UserAuthDetailReadModelalso aReadModel? (Since it is NOT returned fromQuery, but return fromReader) - If Question #1 is
Query, does it mean as long as theQueryonly performs query/read withReadModel, the name ofQuerydoes not limit toCRUDstyle of prefix (e.g.GetUserAuthDetailQuery)? - If Question #1 is
Domain Service, would you please give me some idea on how to implement it? (e.g. Class + Method signature) - If Question #1 is neither, would you please give me some insight?
Appreciate any related suggestions and ideas. Thank you!
Aucun commentaire:
Enregistrer un commentaire