示例#1
0
 private static void InitializeMigrations(IApplicationBuilder app)
 {
     using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
     {
         DBinitialize.Initialize(serviceScope);
     }
 }
示例#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(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
                // When you run the app and don't supply any URL segments, it defaults to the "Home" controller and the "Index" method specified above.

                // The Welcome (in HelloWorldController) method contains a parameter "id" that matched the URL template in the MapRoute method. The trailing ? (in id?) indicates the id parameter is optional.
            });
            DBinitialize.EnsureCreated(app.ApplicationServices);
            SeedData.Initialize(app.ApplicationServices);
        }
示例#3
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(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Code}/{action=Index}/{id?}");
            });

            DBinitialize.EnsureCreated(app.ApplicationServices);
        }
示例#4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            //Service Database
            services.AddDbContext <DBContext>(options =>
                                              options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            var serviceProvider = services.BuildServiceProvider();

            DBinitialize.INIT(serviceProvider);
        }
示例#5
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                DBinitialize.EnsureCreated(services);
                SeedData.Initialize(services);
            }
            host.Run();
        }
示例#6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <DBContext>(Options =>
                                              Options.UseSqlServer(Configuration.GetConnectionString("ConnectionStr")));
            services.AddMvc();
            var serviceProvider = services.BuildServiceProvider();

            DBinitialize.INIT(serviceProvider);

            services.AddSpaStaticFiles(c =>
            {
                c.RootPath = "ClientApp/dist/";
            });
        }
示例#7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseSwagger();

            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("v1/swagger.json", "WP Pod API V1");
            });

            app.UseMvc();

            DBinitialize.EnsureCreated(app.ApplicationServices);
            DBinitialize.EnsureSeeded(app.ApplicationServices);
        }
示例#8
0
        // This method gets called by the runtime.
        // Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            app.UseAuthentication();
            app.UseSwagger();

            app.UseSwaggerUI(options => {
                options.SwaggerEndpoint("v1/swagger.json", "Demo Jwt Auth API V1");
            });

            app.UseMvc();
            app.Run(context => {
                context.Response.Redirect("swagger/");
                return(Task.CompletedTask);
            });

            DBinitialize.EnsureCreated(app.ApplicationServices);
        }
示例#9
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    DBinitialize.EnsureCreated(services);
                    SeedData.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured creating and seeding the DB.");                                logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
            host.Run();
        }
示例#10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
            });

            services.AddDbContext <NorthwindContext>(options => {
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
            });
            var serviceProvider = services.BuildServiceProvider();

            DBinitialize.INIT(serviceProvider);


            services.AddControllersWithViews()
            .AddNewtonsoftJson();
            services.AddRazorPages();
        }
示例#11
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            using (var scope = app.ApplicationServices.CreateScope())
            {
                var services = scope.ServiceProvider;

                try
                {
                    DBinitialize.EnsureCreated(services);
                    SeedData.Initialize(services);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }
        }
示例#12
0
 public void Configure(IApplicationBuilder app)
 {
     app.UseMvc();
     DBinitialize.EnsureCreated(app.ApplicationServices);
     SeedData.Initialize(app.ApplicationServices);
 }