public static async Task <ApiResponse <T> > Fetch <T>( this ISqlHattemSessionFactory sessionFactory, Func <ISqlHattemSession, Task <ApiResponse <T> > > handler ) { using var session = sessionFactory.Create(); return(await handler(session) .OnError(ErrorPredicate.Any(), _ => session.Rollback()) .OnSuccess(_ => session.Commit())); }
public static async Task <ApiResponse <T> > Execute <T>( this ISqlHattemSessionFactory sessionFactory, Func <ISqlHattemSession, Task <ApiResponse <T> > > handler, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted ) { using var session = sessionFactory.Create(isolationLevel); return(await handler(session) .OnError(ErrorPredicate.Any(), _ => session.Rollback()) .OnSuccess(_ => session.Commit())); }