예제 #1
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime)
        {
            // If, for some reason, you need a reference to the built container, you
            // can use the convenience extension method GetAutofacRoot.
            //this.AutofacContainer = app.ApplicationServices.GetAutofacRoot();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseInfrastructure();
            app.UseInitializers();
            app.UseRouting();
            app.UseStaticFiles();
            // app.UseAuthentication();
            // app.UseAuthorization();
            // app.UseAccessTokenValidator();
            app.UseServiceId();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapGet("/", async context =>
                                 await context.Response.WriteAsync(context.RequestServices.GetService <AppOptions>().Name));
                endpoints.MapHealthChecks("/healthz");
            });

            app.UseAllForwardedHeaders();
            app.UseErrorHandler();
            app.UseSwaggerDocs();
            applicationLifetime.ApplicationStopped.Register(() =>
            {
                AutofacContainer.Dispose();
            });
        }
예제 #2
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime applicationLifetime)
        {
            // If, for some reason, you need a reference to the built container, you
            // can use the convenience extension method GetAutofacRoot.
            this.AutofacContainer = app.ApplicationServices.GetAutofacRoot();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseInfrastructure();
            app.UseInitializers();
            app.UseRouting();
            app.UseAuthorization();
            app.UseDefaultFiles(); //set startup url to index static file
            app.UseStaticFiles();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapGet("/", async context =>
                                 await context.Response.WriteAsync(GetHomeHtml(context)));
                endpoints.MapHealthChecks("/healthz");
                var signalrOptions = app.ApplicationServices.GetRequiredService <SignalrOptions>();
                endpoints.MapHub <GameHub>($"/{signalrOptions.Hub}");
            });
            app.UseAllForwardedHeaders();
            app.UseSwaggerDocs();
            app.UseErrorHandler();
            app.UseServiceId();
            applicationLifetime.ApplicationStopped.Register(() =>
            {
                AutofacContainer.Dispose();
            });
        }
예제 #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, IApplicationLifetime appLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

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

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

            // 路由
            ConfigRoute(app);

            //依赖注入
            appLifetime.ApplicationStopped.Register(() => { AutofacContainer.Dispose(); });

            var jobOptions = new BackgroundJobServerOptions
            {
                Queues      = new[] { "test", "default" },     //队列名称,只能为小写
                WorkerCount = Environment.ProcessorCount * 10, //并发任务数
                ServerName  = "hangfire1",                     //服务器名称
            };
            var hang_options = new DashboardOptions
            {
                Authorization = new[] { new HangfireAuthorizationFilter() }
            };

            app.UseHangfireServer(jobOptions);                   //启动Hangfire服务
            app.UseHangfireDashboard("/hangfire", hang_options); //启动hangfire面板
        }
예제 #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, IApplicationLifetime applicationLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseAuthentication()
            .UseHttpsRedirection()
            .UseMvc()
            .UseSwagger()
            .UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"/swagger/{Configuration["Api:Name"]}/swagger.json", Configuration["Api:Name"]);
            });

            applicationLifetime.ApplicationStopped.Register(() => AutofacContainer.Dispose());
        }
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime applicationLifetime, IConsulClient client,
                              IStartupInitializer startupInitializer, SignalrOptions signalrOptions)
        {
            // If, for some reason, you need a reference to the built container, you
            // can use the convenience extension method GetAutofacRoot.
            this.AutofacContainer = app.ApplicationServices.GetAutofacRoot();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseInitializers();
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapGet("/", async context =>
                                 await context.Response.WriteAsync(context.RequestServices.GetService <AppOptions>().Name));
                endpoints.MapHealthChecks("/healthz");
                endpoints.MapHub <GameHub>("/gameHub");
            });
            app.UseAllForwardedHeaders();
            app.UseSwaggerDocs();
            app.UseErrorHandler();
            app.UseServiceId();

            app.UseRabbitMq()
            .SubscribeEvent <GameEventSourceAdded>(@namespace: "game-event-sources");

            var consulServiceId = app.UseConsul();

            applicationLifetime.ApplicationStopped.Register(() =>
            {
                client.Agent.ServiceDeregister(consulServiceId);
                AutofacContainer.Dispose();
            });
        }
 public void Dispose()
 {
     Bus?.Stop();
     AutofacContainer?.Dispose();
     MartenDatabaseFixture?.Dispose();
 }
예제 #7
0
 public void CleanUp()
 {
     context.Dispose();
     AutofacContainer.Dispose();
 }
 public void Dispose()
 {
     AutofacContainer?.Dispose();
 }
예제 #9
0
        protected override void OnDispose()
        {
            base.OnDispose();

            AutofacContainer.Dispose();
        }