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:
Controller
sendAuthenticateUserQuery
toMediatr
Mediatr
executeAuthenticateUserQueryHandler.Handle()
AuthenticateUserQueryHandler
getUserAuthDetailReadModel
fromUserAuthDetailReader
- Do authenticate with query's
UserId
+Password
andUserAuthDetailReadModel
- Return
UserAuthResult
Questions Time!
- From the description above,
AuthenticateUserQuery
only performs query/read, is it a validQuery
orDomain Service
- If Question #1 is
Query
, isUserAuthResult
aReadModel
? (Since it is returned from aQuery
) - If Question #2 is a YES, is
UserAuthDetailReadModel
also aReadModel
? (Since it is NOT returned fromQuery
, but return fromReader
) - If Question #1 is
Query
, does it mean as long as theQuery
only performs query/read withReadModel
, the name ofQuery
does not limit toCRUD
style 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