Example #1
0
 //运行时调用此方法。使用此方法配置HTTP请求管道。
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     else
     {
         app.UseExceptionHandler("/Home/Error");
     }
     app.UseStaticFiles();
     app.UseCookiePolicy();
     app.UseRouting();
     app.UseSession();
     app.UseAuthentication();
     app.UseAuthorization();
     app.UseEndpoints(endpoints =>
     {
         endpoints.MapControllerRoute(
             name: "default",
             pattern: "{controller=Home}/{action=Index}/{id?}");
         endpoints.MapRazorPages();
         endpoints.MapAreaControllerRoute(
             name: "areas",
             areaName: "Admin",
             pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
         endpoints.MapRazorPages();
         endpoints.MapHub <SignalRHelper>("/Memo");
     });
     AppDependencyResolver.Init(app.ApplicationServices);
 }
Example #2
0
        private static void UseAppInner(IApplicationBuilder app, IHostingEnvironment env)
        {
            AppDependencyResolver.Init(app.ApplicationServices);
            app.UseStatusCodePagesWithReExecute("/Errors/Statuses/{0}");


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

            app.UseMiddleware <AjaxExceptionHandlerMiddleware>();

            app.ApplicationServices.GetRequiredService <WorkersQueue>().Init();

            app.UseStaticFiles();
            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "areaRoute",
                                template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            app.UseAppWebSwagger();
        }
Example #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)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // 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.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

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

            AppDependencyResolver.Init(app.ApplicationServices);
        }
Example #4
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.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

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

            AppDependencyResolver.Init(app.ApplicationServices);
        }
Example #5
0
        public DIFilter_Tests(ITestOutputHelper testOutputHelper)
        {
            _testOutputHelper = testOutputHelper;
            //初始化容器
            services = new ServiceCollection();
            //添加注入关系
            services.AddSingleton <IImportResultFilter, ImportResultFilterTest>();
            services.AddSingleton <IImportHeaderFilter, ImportHeaderFilterTest>();
            services.AddSingleton <IExporterHeaderFilter, TestExporterHeaderFilter1>();
            var serviceProvider = services.BuildServiceProvider();

            AppDependencyResolver.Init(serviceProvider);
            _testOutputHelper.WriteLine("DIFilter_Tests");
        }
Example #6
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("PortfolioDatabase")));

            services.AddDbContext <PostgresDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("Portfolio")));

            services.AddScoped <IDataAccessProvider, DataAccessPostgreSqlProvider>();

            EntityProperties.UseDefault   = Configuration.GetValue <bool>("AppConfiguration:EntityProperties:UseDefault");
            EntityProperties.CreatedDate  = Configuration.GetValue <bool>("AppConfiguration:EntityProperties:CreatedDate");
            EntityProperties.ModifiedDate = Configuration.GetValue <bool>("AppConfiguration:EntityProperties:ModifiedDate");
            EntityProperties.IsDeleted    = Configuration.GetValue <bool>("AppConfiguration:EntityProperties:IsDeleted");
            EntityProperties.OwnerId      = Configuration.GetValue <bool>("AppConfiguration:EntityProperties:OwnerId");
            //services.Configure<EntityProperties>(Configuration.GetSection("AppConfiguration:EntityProperties"));

            #region addMvc settings

            services.AddCors(option => option.AddPolicy("AllowAll", p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));

            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling =
                    Newtonsoft.Json.ReferenceLoopHandling.Ignore;

                options.SerializerSettings.ContractResolver =
                    new CamelCasePropertyNamesContractResolver();

                options.SerializerSettings.PreserveReferencesHandling =
                    Newtonsoft.Json.PreserveReferencesHandling.Objects;
            });

            #endregion

            #region Autofac registrations

            var builder = new ContainerBuilder();

            builder.RegisterModule(new AutofacModule());
            builder.Populate(services);

            _currentContainer = builder.Build();

            #endregion

            var applicationServices = new AutofacServiceProvider(_currentContainer);
            AppDependencyResolver.Init(applicationServices);

            return(applicationServices);
        }