public SqlServerCapTransaction( IDispatcher dispatcher, SqlServerOptions sqlServerOptions, IServiceProvider serviceProvider) : base(dispatcher) { if (sqlServerOptions.DbContextType != null) { _dbContext = serviceProvider.GetService(sqlServerOptions.DbContextType) as DbContext; } _diagnosticProcessor = serviceProvider.GetRequiredService <DiagnosticProcessorObserver>(); }
private void AddSqlServerOptions(IServiceCollection services) { var sqlServerOptions = new SqlServerOptions(); _configure(sqlServerOptions); if (sqlServerOptions.DbContextType != null) { services.AddSingleton(x => { using (var scope = x.CreateScope()) { var provider = scope.ServiceProvider; var dbContext = (DbContext)provider.GetService(sqlServerOptions.DbContextType); sqlServerOptions.ConnectionString = dbContext.Database.Connection.ConnectionString; return(sqlServerOptions); } }); } else { services.AddSingleton(sqlServerOptions); } }