コード例 #1
0
ファイル: Startup.cs プロジェクト: kakubila/magic
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            foreach (var ctrlType in app.GetControllerTypes())
            {
                Kernel.Bind(ctrlType).ToSelf().InScope(RequestScope);
            }

            Kernel.Bind <IConfiguration>().ToConstant(Configuration);
            InitializeDatabase.Initialize(Kernel, Configuration, RequestScope);
            Configurator.ConfigureNinject(Kernel, Configuration);

            app.UseExceptionHandler(errorApp => errorApp.Run(async context =>
            {
                context.Response.StatusCode  = 500;
                context.Response.ContentType = "application/json";
                var ex     = context.Features.Get <IExceptionHandlerPathFeature>();
                var logger = LogManager.GetLogger(ex?.Error.GetType() ?? typeof(Startup));
                var msg    = ex?.Error.Message ?? "Unhandled exception";
                logger.Error("At path: " + ex?.Path);
                logger.Error(msg, ex?.Error);
                var response = new JObject
                {
                    ["message"] = msg,
                };
                await context.Response.WriteAsync(response.ToString(Formatting.Indented));
            }));

            app.UseHttpsRedirection();
            app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyHeader());

            Configurator.ConfigureApplication(app, Configuration);

            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TITLE"));

            Configurator.ExecuteStartups(Kernel, Configuration);
        }