public static void DoDapperService(this IServiceProvider serviceProvider, DbConfig dbConfig, Action <IUnitOfWork> action) { using (DatabaseSession databaseSession = new DatabaseSession(dbConfig)) { IUnitOfWork unitOfWork = databaseSession.UnitOfWork; unitOfWork.Begin(); try { action(unitOfWork); unitOfWork.Commit(); } catch { unitOfWork.Rollback(); throw; } } }
public static async Task DoDapperServiceAsync(this IServiceProvider serviceProvider, DbConfig dbConfig, Func <IUnitOfWork, Task> action) { using (DatabaseSession databaseSession = new DatabaseSession(dbConfig)) { IUnitOfWork unitOfWork = databaseSession.UnitOfWork; unitOfWork.Begin(); try { await action(unitOfWork); unitOfWork.Commit(); } catch { unitOfWork.Rollback(); throw; } } }
public static TResult DoDapperService <TResult>(this IServiceProvider serviceProvider, DbConfig dbConfig, Func <IUnitOfWork, TResult> action) { using (DatabaseSession databaseSession = new DatabaseSession(dbConfig)) { IUnitOfWork unitOfWork = databaseSession.UnitOfWork; unitOfWork.Begin(); try { var result = action(unitOfWork); unitOfWork.Commit(); return(result); } catch { unitOfWork.Rollback(); throw; } } }