How to use transaction through multiple services? #22
-
Hello, thanks for great series.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Good question. I typically make my service methods implement a transactional boundary so that I don't need to share the transaction outside of it. In the example you have, you don't have a shared transaction as the You could model your |
Beta Was this translation helpful? Give feedback.
Good question. I typically make my service methods implement a transactional boundary so that I don't need to share the transaction outside of it. In the example you have, you don't have a shared transaction as the
fileStorageService
isn't likely transactional (assuming it's disk-backed or S3-backed). You can end up with the file on your storage service but yourCreateUser()
could fail.You could model your
Tx
inside your application domain but that assumes that all your services that usemyapp.Tx
are transactional. Transactions really only make sense within a single service (e.g. asqlite
layer) as you can't easily implement transactions across multiple layers or implementations.