private void SetupRequestContext(RequestContext context, DataSourceChoice sourceChoice) { context.Setup(SmartSqlOptions); InitDataSource(context, sourceChoice); }
public async Task <T> ExecuteWrapAsync <T>(Func <IDbConnectionSession, Task <T> > execute, RequestContext context, DataSourceChoice sourceChoice = DataSourceChoice.Write) { SetupRequestContext(context, sourceChoice); if (CacheManager.TryGet <T>(context, out T cachedResult)) { return(cachedResult); } return(await WrapWithTransactionAsync <T>(context, async (dbSession) => { if (dbSession == null) { var dataSource = DataSourceFilter.Elect(context); dbSession = SessionStore.GetOrAddDbSession(dataSource); } try { var result = await execute(dbSession).ConfigureAwait(false); CacheManager.RequestExecuted(dbSession, context); CacheManager.TryAdd <T>(context, result); return result; } catch (Exception ex) { _logger.LogError(ex.HelpLink, ex, ex.Message); throw ex; } finally { if (dbSession.LifeCycle == DbSessionLifeCycle.Transient) { SessionStore.Dispose(); } } })); }
public IDbConnectionSession BeginTransaction(RequestContext context) { InitDataSource(context, DataSourceChoice.Write); return(BeginTransaction(context, IsolationLevel.Unspecified)); }
public int Execute(RequestContext context) { return(ExecuteWrap((dbSession) => CommandExecuter.ExecuteNonQuery(dbSession, context), context)); }