示例#1
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, IDatabaseManager databaseManager, IApplicationLifetime applicationLifetime, ILogger logger)
        {
            applicationLifetime.ApplicationStopping.Register(OnShutdown, app);

            //To dispose of resources that have been resolved in the application container
            //http://autofaccn.readthedocs.io/en/latest/integration/aspnetcore.html#quick-start-without-configurecontainer
            applicationLifetime.ApplicationStopped.Register(() => _applicationContainer.Dispose());

            try
            {
                if (!env.IsStaging() && !env.IsProduction())
                {
                    databaseManager.CreateEmptyDatabaseIfNotExistsAsync().GetAwaiter().GetResult();
                }
                databaseManager.MigrateToLatestVersionAsync();
            }
            catch (Exception ex)
            {
                logger.Event("UnableToSetupDatabase").With.Message("Unable to seed database.").Exception(ex).AsFatal();
                throw;
            }

            // TODO: add `&& !env.IsStaging()` when testing will be passed
            if (!env.IsProduction())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseDatabaseErrorPage();

                // Enable middleware to serve generated Swagger as a JSON endpoint.
                app.UseSwagger();
                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint($"/swagger/v1.0/swagger.json", "Versioned Api v1.0");
                });
            }

            app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            app.UseCorrelationId();
            app.UseAuthentication();
            app.UseSignalR(routes =>
            {
                routes.MapHub <ChatHub>("/chat");
            });
            app.UseMiddleware <ExceptionHandlingMiddleware>();
            app.UseMvc();
        }