Exemple #1
0
        private async void InitializeDatabase(IApplicationBuilder app)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                var roleManager = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >();

                await RoleInitializer.SeedRoles(roleManager);

                var context = serviceScope.ServiceProvider.GetService <CritiquesShelfDbContext>();

                // Not working, sadly
                var googleApiConfig = serviceScope.ServiceProvider.GetService <GoogleBooksApiConfig>();

                var key         = Configuration["GoogleBooksApi:Key"];
                var forceUpdate = bool.Parse(Configuration["GoogleBooksApi:ForceUpdate"]);

                googleApiConfig = new GoogleBooksApiConfig
                {
                    Key         = key,
                    ForceUpdate = forceUpdate
                };

                await BookInitializer.SeedBooks(context, googleApiConfig);
            }
        }
        protected override void Seed(SerwisKsiazkowy.DAL.BookContext context)
        {
            BookInitializer.SeedBookData(context);
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
        }