예제 #1
0
        private async Task InitializeDatabase(IApplicationBuilder app)
        {
            var clientUrls = new Dictionary <string, string>
            {
                { "AngularClient", this.Configuration.GetValue <string>("AngularClient") },
            };

            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                serviceScope.ServiceProvider.GetRequiredService <ApplicationDbContext>().Database.Migrate();

                serviceScope.ServiceProvider.GetRequiredService <PersistedGrantDbContext>().Database.Migrate();

                var context = serviceScope.ServiceProvider.GetRequiredService <ConfigurationDbContext>();

                context.Database.Migrate();

                if (!await context.Clients.AnyAsync())
                {
                    context.Clients.AddRange(IdentityServiceConfiguration.GetClients(clientUrls).Select(client => client.ToEntity()));
                }

                if (!await context.IdentityResources.AnyAsync())
                {
                    context.IdentityResources.AddRange(IdentityServiceConfiguration.GetResources().Select(resource => resource.ToEntity()));
                }

                if (!await context.ApiResources.AnyAsync())
                {
                    context.ApiResources.AddRange(IdentityServiceConfiguration.GetApis().Select(api => api.ToEntity()));
                }

                await context.SaveChangesAsync();
            }
        }
예제 #2
0
        public async Task SeedAsync(ConfigurationDbContext context, IConfiguration configuration)
        {
            //callbacks urls from config:
            var clientUrls = new Dictionary <string, string>
            {
            };

            if (!await context.Clients.AnyAsync())
            {
                context.Clients.AddRange(IdentityServiceConfiguration.GetClients(clientUrls).Select(client => client.ToEntity()));
            }

            if (!await context.IdentityResources.AnyAsync())
            {
                context.IdentityResources.AddRange(IdentityServiceConfiguration.GetResources().Select(resource => resource.ToEntity()));
            }

            if (!await context.ApiResources.AnyAsync())
            {
                context.ApiResources.AddRange(IdentityServiceConfiguration.GetApis().Select(api => api.ToEntity()));
            }

            await context.SaveChangesAsync();
        }