public ActionResult <string> Database() { var diagnostics = new DatabaseDiagnostics(); DbContext dbContext = _dbContextProvider.Get <DbContext>(); DbConnection connection = dbContext?.Database.GetDbConnection(); if (connection != null) { diagnostics.ServerName = connection.DataSource; diagnostics.DatabaseName = connection.Database; } return(new OkObjectResult(diagnostics)); }
public async Task <OperationResultOf <TResult> > TryUseAsync <TResult>( Func <DbContext, Task <OperationResultOf <TResult> > > usage) { try { if (_dbContextProvider.DisposeAfterUsage) { await using var dbContext = _dbContextProvider.Get(); return(await usage(dbContext) .ConfigureAwait(false)); } return(await usage(_dbContextProvider.Get()) .ConfigureAwait(false)); } catch (Exception ex) { return(ex.AsFailedOpResOf <TResult>()); } }