Exemplo n.º 1
0
        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>();
        }
Exemplo n.º 2
0
        public void AddServices(IServiceCollection services)
        {
            services.AddSingleton <IStorage, SqlServerStorage>();
            services.AddScoped <IStorageConnection, SqlServerStorageConnection>();
            services.AddScoped <ICapPublisher, CapPublisher>();
            services.AddTransient <IAdditionalProcessor, DefaultAdditionalProcessor>();

            var sqlServerOptions = new SqlServerOptions();

            _configure(sqlServerOptions);

            if (sqlServerOptions.DbContextType != null)
            {
                var provider     = TempBuildService(services);
                var dbContextObj = provider.GetService(sqlServerOptions.DbContextType);
                var dbContext    = (DbContext)dbContextObj;
                sqlServerOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
            }
            services.AddSingleton(sqlServerOptions);
        }
        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.GetDbConnection().ConnectionString;
                        return(sqlServerOptions);
                    }
                });
            }
            else
            {
                services.AddSingleton(sqlServerOptions);
            }
        }