Exemplo n.º 1
0
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddHttpClient();
     services.AddHttpContextAccessor();
     services.AddTransient <BlogPostBuilder>();
     services.AddTransient <ExistingBlogPostBuilder>();
     services.AddSecurity(_configuration, _environment);
     services.AddDbContextPool <AppDbContext>(o =>
     {
         var connectionString = _connectionStringFactory.Create();
         o.UseSqlServer(connectionString);
     });
     services.AddConfiguredMvc();
     services.AddAutoMapper(typeof(Program));
     services.AddMediatR(typeof(Startup));
     services.AddSwaggerDocument(_swaggerConfiguration.ConfigureSwagger);
     services.ScanServices(_environment.EnvironmentName);
     services.AddMailgun();
     services.AddTransient(typeof(HandlerContext <>));
 }
Exemplo n.º 2
0
        public static void InitDb(IConfiguration configuration, IHostingEnvironment environment)
        {
            var services = new ServiceCollection();

            services.AddDbContext <AppDbContext>(o =>
            {
                var factory          = new ConnectionStringFactory(configuration, environment);
                var connectionString = factory.Create();
                o.UseSqlServer(connectionString);
            });
            var serviceProvider = services.BuildServiceProvider();

            using (serviceProvider.CreateScope())
            {
                var context = serviceProvider.GetService <AppDbContext>();

                context.Database.Migrate();
            }
            serviceProvider.Dispose();
        }