public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            DatabaseSeeding.Seed();
            host.Run();
        }
Example #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var context = scope.ServiceProvider.GetService <DatabaseContext>();
                context.Database.Migrate();
                DatabaseSeeding.SeedDatabase(context);
            }
        }
Example #3
0
        private async Task InitialiseDatabase(IApplicationBuilder app, IHostingEnvironment environment)
        {
            using (IServiceScope scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                ProductRepositoryDbContext productRepositoryDbContext = scope.ServiceProvider.GetRequiredService <ProductRepositoryDbContext>();

                DatabaseSeeding.InitialiseDatabase(productRepositoryDbContext);
            }
        }
Example #4
0
        /// <summary>
        /// Initialises the database.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <returns></returns>
        private static async Task InitialiseDatabase(IServiceProvider serviceProvider)
        {
            using (IServiceScope scope = serviceProvider.GetService <IServiceScopeFactory>().CreateScope())
            {
                SubscriptionServiceConfigurationContext subscriptionServiceConfigurationContext = scope.ServiceProvider.GetRequiredService <SubscriptionServiceConfigurationContext>();

                DatabaseSeeding.InitialiseDatabase(subscriptionServiceConfigurationContext);
            }
        }
        /// <summary>
        /// Initialises the database.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="environment">The environment.</param>
        private async Task InitialiseDatabase(IApplicationBuilder app,
                                              IHostingEnvironment environment)
        {
            using (IServiceScope scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                MobileConfiguration mobileConfiguration = scope.ServiceProvider.GetRequiredService <MobileConfiguration>();

                DatabaseSeeding.InitialiseDatabase(mobileConfiguration);
            }
        }
        /// <summary>
        /// Initialises the database.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="environment">The environment.</param>
        private async Task InitialiseDatabase(IApplicationBuilder app,
                                              IHostingEnvironment environment)
        {
            using (IServiceScope scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                ManagementAPIReadModel managementApiReadModel = scope.ServiceProvider.GetRequiredService <ManagementAPIReadModel>();

                SeedingType seedingType = Startup.Configuration.GetValue <SeedingType>("SeedingType");

                DatabaseSeeding.InitialiseDatabase(managementApiReadModel, seedingType);
            }
        }
Example #7
0
        private static void InitializeDatabase(IWebHost host)
        {
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    DatabaseSeeding.InitializeAsync(services).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the database.");
                }
            }
        }
        /// <summary>
        /// Initialises the database.
        /// </summary>
        /// <param name="app">The application.</param>
        /// <param name="environment">The environment.</param>
        private async Task InitialiseDatabase(IApplicationBuilder app, IHostingEnvironment environment)
        {
            using (IServiceScope scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                PersistedGrantDbContext persistedGrantDbContext = scope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>();
                ConfigurationDbContext  configurationDbContext  = scope.ServiceProvider.GetRequiredService <ConfigurationDbContext>();
                AuthenticationDbContext authenticationDbContext = scope.ServiceProvider.GetRequiredService <AuthenticationDbContext>();

                var seedingType = Startup.Configuration.GetValue <SeedingType>("SeedingType");

                if (seedingType == SeedingType.Production)
                {
                    throw new NotImplementedException("Production setup not complete yet");
                }

                DatabaseSeeding.InitialisePersistedGrantDatabase(persistedGrantDbContext, seedingType);
                DatabaseSeeding.InitialiseConfigurationDatabase(configurationDbContext, seedingType);
                DatabaseSeeding.InitialiseAuthenticationDatabase(authenticationDbContext, seedingType);
            }
        }
Example #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, LibraryContext libraryContext,
                                    ApplicationDbContext identityContext)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseIdentity();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            //This was left in the project in case you want
            //to use it to create your own test data.

            //DbInitializer.Initialize(context);

            libraryContext.Database.Migrate();

            identityContext.Database.Migrate();

            await DatabaseSeeding.Initialize(app.ApplicationServices);
        }