/// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            PersonalityTestDbContext dbContext,
            DatabaseSeeder seeder)
        {
            dbContext.Database.EnsureCreated();
            seeder.SeedDatabase();

            DatabaseConfiguration.EnsureEventStoreIsCreated(Configuration);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseCrossOriginResourceSharing();
            app.UseSwagger("Personality Test");

            app.UseHttpsRedirection();
            app.UseMvc();
        }
示例#2
0
        public static void Main(string[] args)
        {
            // Load appsettings.json file
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            Configuration = builder.Build();

            var host = BuildWebHost(args);

            // Seed database
            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <UniAccomodationDbContext>();
                    var options = Configuration.GetSection("Identity").Get <MyIdentityOptions>();
                    // Using migrations to handle database schema
                    context.Database.Migrate();
                    // Seed database
                    DatabaseSeeder.SeedDatabase(services, options, context).Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseSession();
            app.UseAuthentication();
            app.UseRouting();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            DatabaseSeeder.SeedDatabase(app);
            IdentityDatabaseSeeder.SeedIdentityDatabase(app);
        }
示例#4
0
 private void SeedDatabaseExecute()
 {
     using (IUnitOfWork context = ServiceLocator.Current.GetInstance <IUnitOfWork>("LocalDatabase"))
     {
         var dataSeeder = new DatabaseSeeder(context);
         dataSeeder.SeedDatabase();
     }
 }
示例#5
0
        /// <summary>
        /// Constructor of the class
        /// </summary>
        /// <param name="context"></param>
        public ContatoController(AgendaContext context)
        {
            _context = context;

            DatabaseSeeder databaseSeeder = new DatabaseSeeder(_context);

            databaseSeeder.SeedDatabase();
        }
示例#6
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.ApplyConfiguration(new UserAccountConfiguration());
            builder.ApplyConfiguration(new CreditConfiguration());
            builder.ApplyConfiguration(new CreditCategoryConfiguration());

            DatabaseSeeder.SeedDatabase(builder);
        }
示例#7
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

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

                var context        = services.GetRequiredService <BudgetDbContext>();
                var colorGenerator = services.GetRequiredService <IColorGenerator>();
                DatabaseSeeder.SeedDatabase(context, colorGenerator);
            }

            host.Run();
        }
        /// <summary>
        /// This method gets called by the runtime.
        /// Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app">
        /// Provides the mechanisms to configure an application's request pipeline.
        /// </param>
        /// <param name="env">
        /// Provides information about the web hosting environment an application is running in.
        /// </param>
        /// <param name="loggerFactory">
        /// Represents a type used to configure the logging system
        /// and create instances of ILogger from the registered ILoggerProviders.
        /// </param>
        /// <param name="userManager">
        /// Managing user in a persistence store.
        /// </param>
        /// <param name="dbContext">
        /// Application class for the Entity Framework database context used for identity.
        /// </param>
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            UserManager <User> userManager,
            ApplicationDbContext dbContext,
            DatabaseSeeder seeder)
        {
            // ensure data stores
            dbContext.Database.EnsureCreated();
            DatabaseConfiguration.EnsureEventStoreIsCreated(Configuration);

            if (!env.IsEnvironment(Environment.IntegrationTests))
            {
                DatabaseConfiguration.AddDefaultAdminAccountIfNoneExisting(userManager, Configuration).Wait();
                seeder.SeedDatabase().Wait();
            }

            if (!env.IsDevelopment())
            {
                app.UseHsts();
                app.UseHttpsRedirection();
            }

            app.UseCors(builder => builder
                        .SetIsOriginAllowedToAllowWildcardSubdomains()
                        .WithOrigins("http://localhost:3000", "https://jbet.net")
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            loggerFactory.AddLogging(Configuration.GetSection("Logging"));

            app.UseSwagger("Jbet");

            app.UseStaticFiles();
            app.UseAuthentication();

            // soon app.UseSignalR

            app.UseMvc();
        }
示例#9
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseCors("Frontend");

            app.UseIdentityServer();

            app.UseHttpsRedirection();
            app.UseMvc();

            DatabaseSeeder.SeedDatabase(app);
        }
示例#10
0
文件: Startup.cs 项目: vanbinh85/cafe
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, UserManager <User> userManager, ApplicationDbContext dbContext, DatabaseSeeder seeder)
        {
            dbContext.Database.EnsureCreated();
            DatabaseConfiguration.EnsureEventStoreIsCreated(Configuration);

            if (!env.IsEnvironment(Environment.IntegrationTests))
            {
                DatabaseConfiguration.AddDefaultAdminAccountIfNoneExisting(userManager, Configuration).Wait();
                seeder.SeedDatabase().Wait();
            }

            if (!env.IsDevelopment())
            {
                app.UseHsts();
                app.UseHttpsRedirection();
            }

            app.UseCors(builder => builder
                        .SetIsOriginAllowedToAllowWildcardSubdomains()
                        .WithOrigins("http://localhost:3000", "https://*.devadventures.net")
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());

            loggerFactory.AddLogging(Configuration.GetSection("Logging"));

            app.UseSwagger("Cafe");
            app.UseStaticFiles();
            app.UseAuthentication();

            // It's very important that UseAuthentication is called before UseSignalR
            app.UseSignalR(routes =>
            {
                routes.MapHub <ConfirmedOrdersHub>("/confirmedOrders");
                routes.MapHub <HiredWaitersHub>("/hiredWaiters");
                routes.MapHub <TableActionsHub>("/tableActions");
            });

            app.UseMvc();
        }
示例#11
0
 public static void ClassInitialize(TestContext context)
 {
     DatabaseSeeder.SeedDatabase();
 }
示例#12
0
 public FakeDatabaseService()
 {
     DatabaseSeeder.SeedDatabase();
 }
示例#13
0
 public void TestSetUp()
 {
     _seeder.SeedDatabase();     // put some test data from a script
 }
示例#14
0
        public void DatabaseSeederTest()
        {
            var seeder = new DatabaseSeeder();

            seeder.SeedDatabase(new CcgDbContext());
        }