Ejemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                         .AddJsonFile("sharedSettings.json", optional: false, reloadOnChange: true)
                         .Build();

            var host = CreateHostBuilder(args, config).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    var eventBus = services.GetRequiredService <IEventBus>();

                    var context = services.GetRequiredService <UserDbContext>();

                    if (context.Database.IsSqlServer())
                    {
                        context.Database.Migrate();
                    }

                    var configuration = services.GetRequiredService <IConfiguration>();

                    await UserDbContextSeed.SeedSampleDataAsync(eventBus, context, configuration);
                }
                catch (Exception ex)
                {
                }
            }

            host.Run();
        }
Ejemplo n.º 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, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseStatusCodePages();

                app.UseBrowserLink();
            }

            app.UseStaticFiles( );

            // Add Identity which allows user info to be excluded from the requests and responses
            app.UseIdentity();

            // Auth 1/2: Allow cookie authentication
            //app.UseCookieAuthentication(new CookieAuthenticationOptions
            //{
            //    AuthenticationScheme = "Cookie",
            //    AutomaticAuthenticate = true,
            //    AutomaticChallenge = true,
            //    LoginPath = new PathString("/UserAccount/Login"),
            //    AccessDeniedPath = new PathString("/UserAccount/AccessDenied")
            //});

            app.UseClaimsTransformation(ClaimsProvider.AddClaims);

            app.UseMvcWithDefaultRoute();

            UserDbContextSeed.Seed(app.ApplicationServices).Wait();
        }
Ejemplo n.º 3
0
        public async static Task Main(string[] args)
        {
            //Read Configuration from appSettings
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                         .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true, reloadOnChange: true)
                         .AddUserSecrets <Startup>(optional: true, reloadOnChange: true)
                         .Build();

            //Initialize Logger
            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .ReadFrom.Configuration(config)
                         .CreateLogger();

            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    //Seed Default Users
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await UserDbContextSeed.SeedEssentialsAsync(userManager, roleManager);
                }
                catch (Exception ex)
                {
                    Log.Fatal(ex, "The HostBuilder terminated unexpectedly");
                }
                finally
                {
                    Log.CloseAndFlush();
                }
            }

            host.Run();
        }
Ejemplo n.º 4
0
        public async static Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    //Seed Default Users
                    var userManager = services.GetRequiredService <UserManager <ApplicationUser> >();
                    var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                    await UserDbContextSeed.SeedEssentialsAsync(userManager, roleManager);
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }