Exemple #1
0
        public IServiceCollection Bootstrap(IServiceCollection services)
        {
            var config    = services.BuildServiceProvider().GetRequiredService <IConfiguration>();
            var sqlConfig = new SQLPluginConfig();

            config.Bind("OldSQLPlugin", sqlConfig);

            services.AddScoped <DbConnection>((serviceProvider) =>
            {
                // using System.Data.SqlClient
                var dbConnection = new SqlConnection(sqlConfig.ConnectionString);
                dbConnection.Open();
                return(dbConnection);
            });

            services.AddScoped <DbContextOptions>((serviceProvider) =>
            {
                var dbConnection = serviceProvider.GetService <DbConnection>();
                return(new DbContextOptionsBuilder <ProductsDbContext>()
                       .UseSqlServer(dbConnection)
                       .Options);
            });

            services.AddScoped <ProductsDbContext>((serviceProvider) =>
            {
                var options = serviceProvider.GetService <DbContextOptions>();
                var context = new ProductsDbContext(options);
                return(context);
            });

            return(services);
        }
Exemple #2
0
 internal SqlProductsRepository(ProductsDbContext dbContext)
 {
     this.dbContext = dbContext;
 }