Exemplo n.º 1
0
        public static void SetContextOptions(string connectionStringName = "Default")
        {
            var configuration = ConfigurationProvider.GetConfiguration();

            var dbContextOptionsBuilder = new DbContextOptionsBuilder <AuditorDbContext>();
            var connectionString        = configuration.GetConnectionString(connectionStringName);

            dbContextOptionsBuilder.UseSqlServer(connectionString);

            ContextOptions   = dbContextOptionsBuilder.Options;
            ConnectionString = connectionString;
        }
Exemplo n.º 2
0
        public static IConfigurationRoot ConfigureServices(IServiceCollection services)
        {
            // Build configuration
            _configuration = ConfigurationProvider.GetConfiguration();


            //Add dbContext
            services.AddDbContext <AuditorDbContext>(options =>
                                                     options.UseSqlServer(_configuration.GetConnectionString("Default"),
                                                                          x => x.MigrationsAssembly(nameof(DataSource))));

            // Add access to generic IConfigurationRoot
            services.AddSingleton <IConfigurationRoot>(_configuration);


            return(_configuration);
        }