Replies: 1 comment
-
You can create a new pipeline in mediatr(behavior) that accepts request of type T. This behavior can get an instance of DbContext and in its handle method start a transaction, move on to next item in pipeline and then commit the transaction at the end. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I have a question how would we implement atomic consistency using this template.
For example we have a system which has basic CRUD commands and queryies.
Commands for altering Domain entity "User"
CreateUserCommand
UpdateUserCommand
DeleteUserCommand
Commands for altering Domain entity "
UserDepartment
" which is a bridge(join) table between "User
" and "Department
" entities.AssignUserToDepartmentCommand
UpdateUserDepartmentCommand
RemoveUserFromDepartmentCommand
Now we have a case when existing user is assigned to multiple Departments, ok. Good.
Now, let's say that user is no longer working in the firm and we have delete him/her.
We would issue a command "
DeleteUserCommand
" in WebAPI controller that would call "DeleteUserComandHandler
" usingMediatR.Send(DeleteUserCommand)
.Now, that handler would have to call another command "
RemoveUserFromDepartmentCommand
" and after that command executed succesfully it would delete the user from repository.If "
RemoveUserFromDepartmentCommand
" have failed for any reason. The whole process should fail. And vice versa. If "RemoveUserFromDepartmentCommand
" was sucessful, but removing the very own user from repositoroy have failed, whole process should fail, and transactions in DB should not be commited.So in DDD words. How would we use aggregates in this project template and ensure ther
ATOMIC
execution ( all or nothing inside one DB transacion)Beta Was this translation helpful? Give feedback.
All reactions