-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hello!
I've been thinking about abstracting repositories (including transactions) for the last week. I've been writing, looking at other people's code, rewriting my own, googling, and much more. Considering the different transaction handling in different libraries, I came to the idea that IoC might help, but for now it's just an idea and I don't even have a PoC.
Here is an example of an Executor trait that can be used instead of creating your own traits for transaction and single connection:
trait IExecutor {
type Connection;
type Transaction;
async fn in_connection<'a, 'b, Fun, Fut, Ret>(
&'a mut self,
fun: Fun
) -> Result<Ret, Error>
where
'a: 'b,
Fun: FnOnce(&'b mut Self::Connection) -> Fut,
Fut: std::future::Future<Output = Ret>;
async fn in_transaction<'a, 'b, Fun, Fut, Ret>(
&'a mut self,
fun: Fun
) -> Result<Ret, Error>
where
'a: 'b,
Fun: FnOnce(&'b mut Self::Transaction) -> Fut,
Fut: std::future::Future<Output = Ret>;
}But I'm still thinking how this would work in the repository <-> service relation.
What do you think about it?
Metadata
Metadata
Assignees
Labels
No labels