コード例 #1
0
 public ProductContext(DbContextOptions <ProductContext> options, IContextSeeder seeder = default) : base(options)
 {
     Seeder = seeder;
     if (Seeder != null)
     {
         Database.EnsureCreated();
     }
 }
コード例 #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,
            IContextSeeder seeder,
            ILoggerFactory loggerFactory)
        {
            this.repositoryModule.Configure(seeder);
            this.serviceModule.Configure();

            loggerFactory.AddLog4Net();

            app.UseStatusCodePages(async context =>
            {
                context.HttpContext.Response.ContentType = "text/plain";
                await context.HttpContext.Response.WriteAsync(
                    "Status code page, status code: " +
                    context.HttpContext.Response.StatusCode);
            });

            if (env.IsEnvironment("Development"))
            {
                app.UseDeveloperExceptionPage();
                loggerFactory.AddDebug(LogLevel.Information);
            }
            else
            {
                app.UseExceptionHandler("/error");
                loggerFactory.AddDebug(LogLevel.Error);
            }

            app.UseStaticFiles();

            app.UseMvc(config =>
            {
                config.MapRoute(
                    name: "Default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" }
                    );
            });
        }
コード例 #3
0
 public void Configure(IContextSeeder seeder)
 {
     seeder.PopulateSeedData().Wait();
 }