// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <ApiUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            var jsonExceptionMiddleware = new JsonExceptionMiddlware(
                app.ApplicationServices.GetRequiredService <IHostingEnvironment>(), app.ApplicationServices.GetRequiredService <ILoggerFactory>());

            app.UseExceptionHandler(new ExceptionHandlerOptions {
                ExceptionHandler = jsonExceptionMiddleware.Invoke
            });

            app.UseMvc();
            app.UseAuthentication();

            //var hangFireAuth = new DashboardOptions
            //{
            //    Authorization = new[]
            //    {
            //        new HangFireAuthorization(app.ApplicationServices.GetService<IAuthorizationService>(),
            //        app.ApplicationServices.GetService<IHttpContextAccessor>())
            //    }
            //};

            app.UseHangfireServer(
                new BackgroundJobServerOptions
            {
                WorkerCount = 1     // limit to 1 connection only.
            });

            app.UseHangfireDashboard("/hangfire");//, options: hangFireAuth);

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Midwolf Solutions Competitions API V1");
            });

            var initialiseIndentDb = new IdentityDBInitialise();

            initialiseIndentDb.SeedData(app.ApplicationServices.GetService <UserManager <ApiUser> >(),
                                        app.ApplicationServices.GetService <RoleManager <IdentityRole> >()).Wait();
        }
예제 #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, UserManager <ApiUser> userManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();

                //var dbContext = app.ApplicationServices.GetRequiredService<ApiDbContext>();
                //AddTestData(dbContext);
            }

            app.UseHttpsRedirection();

            var jsonExceptionMiddleware = new JsonExceptionMiddlware(
                app.ApplicationServices.GetRequiredService <IHostingEnvironment>(), app.ApplicationServices.GetRequiredService <ILoggerFactory>());

            app.UseExceptionHandler(new ExceptionHandlerOptions {
                ExceptionHandler = jsonExceptionMiddleware.Invoke
            });

            app.UseMvc();
            app.UseAuthentication();

            var hangFireAuth = new DashboardOptions
            {
                Authorization = new[]
                {
                    new HangFireAuthorization(app.ApplicationServices.GetService <IAuthorizationService>(),
                                              app.ApplicationServices.GetService <IHttpContextAccessor>())
                }
            };

            app.UseHangfireServer(
                new BackgroundJobServerOptions
            {
                WorkerCount = 1     // limit to 1 connection only.
            });

            app.UseHangfireDashboard("/hangfire", options: hangFireAuth);

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Midwolf Solutions Gaming API V1");
            });

            //IDentityInitializer.SeedUsers(userManager);
            var initialiseIndentDb = new IdentityDBInitialise();

            initialiseIndentDb.SeedData(app.ApplicationServices.GetService <UserManager <ApiUser> >(),
                                        app.ApplicationServices.GetService <RoleManager <IdentityRole> >()).Wait();

            //var mediaType = new MediaTypeHeaderValue("application/json");

            //var formatter = new JsonMediaTypeFormatter();
            //formatter.SupportedMediaTypes.Clear();
            //formatter.SupportedMediaTypes.Add(mediaType);

            //var config = new HttpConfiguration();
            //config.Formatters.Clear();
            //config.Formatters.Add(formatter);
        }