public async Task SeedAsync()
        {
            await IdentityServerSeedData.EnsureSeedData(_serviceProvider);

            if (File.Exists("SeedValues.json"))
            {
                using (var reader = File.OpenText("SeedValues.json"))
                {
                    var values = JToken.Parse(reader.ReadToEnd());
                    await SeedRoles(values["Roles"].Values <string>());
                    await SeedUsers(values["Users"]);
                }
            }
        }
Example #2
0
        public static async Task <int> Main(string[] args)
        {
            try
            {
                IHost host = CreateHostBuilder(args).Build();

                using IServiceScope serviceScope = host.Services.CreateScope();

                IServiceProvider services = serviceScope.ServiceProvider;

                ConfigurationDbContext  configurationDbContext  = services.GetRequiredService <ConfigurationDbContext>();
                ApplicationDbContext    applicationDbContext    = services.GetRequiredService <ApplicationDbContext>();
                PersistedGrantDbContext persistedGrantDbContext = services.GetRequiredService <PersistedGrantDbContext>();

                await applicationDbContext.Database.MigrateAsync();

                await configurationDbContext.Database.MigrateAsync();

                await persistedGrantDbContext.Database.MigrateAsync();

                List <Task> tasks = new List <Task>
                {
                    IdentityServerSeedData.SeedConfiguration(configurationDbContext),
                    IdentityServerSeedData.SeedUserData(services)
                };

                await Task.WhenAll(tasks);

                Log.Information("Starting host...");
                await host.RunAsync();

                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Example #3
0
        public async Task <Unit> Handle(SeedIdentityServerCommand request, CancellationToken cancellationToken)
        {
            await IdentityServerSeedData.SeedAsync(_context);

            return(Unit.Value);
        }