private void CreateServiceCollection() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); var connectionString = ConnectionUtil.GetConnectionString(); //services.AddSingleton(new SqlServerOptions { ConnectionString = connectionString }); services.AddDbContext <TestDbContext>(options => options.UseSqlServer(connectionString)); _services = services; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var connectionString = ConnectionUtil.GetConnectionString(); optionsBuilder.UseSqlServer(connectionString); }