I currently have a set of data access objects called *SlickRepo . So, for example, UserSlickRepo , DistributionSlickRepo , ContentSlickRepo , etc.
Each of these Repositories has methods that basically follow this convention:
trait SomethingRepoImpl extends SomethingRepo { val somethingRepo: SomethingRepo = new SomethingRepoImpl class SomethingRepoImpl extends SomethingRepo with MySlickDatastore { def getSomething(id: UUID): Either[SomethingNotFoundError, Something] = { getDatabase withDynSession {
Now at the service level, we have baked a repo in this class, and we have methods that look like this:
trait SomethingServiceImpl extends SomethingService { dep: SomethingRepo with SomethingElseRepo => val somethingService = new SomethingServiceImpl class SomethingServiceImpl extends SomethingService { def createSomethingGood(): Either[SomeError, (Something, SomethingElse)] = { (dep.somethingRepo.createSomething, dep.somethingElseRepo.createSomethingElse) } } }
Now we want createSomethingGood actually execute two repo methods in a transaction. Since all Slick content is locked in Slick replica methods, what's the best way to do this? I am not opposed to having Slick-specific code in my *ServiceImpl class (I mean weird but good), however that means I have to change the Repo classes to remove the code like getDatabase withDynSession all together and instead transfer in session from service level? For me it just seems ... wrong.
Thadon
source share