Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit of work and multiple object contexts

I have a question on unit of work and repository implementation using multiple object contexts. My application uses data across 3 databases. So that means I have three object contexts each representing one database. I need to get the data from one database but have to filter the data by reading the filter criteria from the other 2 databases. I am passing these three object contexts to the unitofwork constructor so that I will have access to the other two object contexts in my repository. I have searched a lot on internet but could not find any good answer. Can you please suggest if I am doing it right or is there a standard way of handling this kind of scenario.

Thanks, Ajay.

like image 695
ajay Avatar asked Oct 11 '22 05:10

ajay


1 Answers

Holding all three context in the unit-of-work is way to go but the real meaning of such implementation will probably make sense once you need to modify data in more then one database in the single unit-of-work / logical transaction. Until you need to commit data to multiple contexts in the same time your implementation is more like Context factory then unit-of-work. But that is only about naming your implementation. The meaning of your implementation is good.

What I don't agree is the fact that one repository is reading filters from other contexts. Repository should handle only its own data / aggregate roots. That is responsibility of caller (business service) to get filters from other contexts / repositories and pass filter to the main repository needed to get the data.

like image 188
Ladislav Mrnka Avatar answered Dec 21 '22 13:12

Ladislav Mrnka