Posted 12 May 2018 - 04:15 AM
I think it's too abstract for its own good. Not just your question but the architecture.
You have these two service things that each do their own thing that you don't really know much about. Do they work with the database? Probably. But what do they do? Will they stop after one query? Does one make database changes that the other implicitly depends on? Must one always execute before the other? If the first one succeeds and the second fails, does the first need to know about it and potentially take action beyond simply reverting its changes? Or are they unrelated and it's just that they both need whatever they do at the same time, and must both be successful for it to matter?
In your shoes I'd be tempted to rewrite both into one service. Or make a new service that copies from both. Whatever so long as there is a single point of responsibility for the sum of actions that are required. Which brings me back to that being the place where transactions should be.
Of course it could be that's what you have there... It feels more like a controller and the two things are models. I don't know.
But as a quick solution, yes: that code would be where the transaction is. It doesn't know for sure that the database is involved, or that there will be multiple queries (beyond presumably one for each dependent service), but at least it is where the work is coordinated.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer