public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            MappingStartup.AddMappings();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseSecurityHeaders()
            .UseStaticFiles()
            .UseSession()
            .UseAuthentication()
            .UseRequestLocalization()
            .UseHealthChecks("/health")
            .UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" }
                    //,constraints: new { controller = new NotEqualRouteContraint("find-an-assessment-opportunity") }
                    );
            });
        }
Exemplo n.º 2
0
        private static void SetupAutomapper()
        {
            var startup = new MappingStartup();

            Mapper.Initialize(cfg =>
            {
                startup.Configure(cfg);
            });
        }
        public void Arrange()
        {
            certificateApprovalsController =
                new CertificateApprovalsController(MockLogger.Object,
                                                   MockHttpContextAccessor.Object,
                                                   MockApiClient
                                                   );

            MappingStartup.AddMappings();
        }
Exemplo n.º 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)
        {
            try
            {
                MappingStartup.AddMappings();

                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                else
                {
                    app.UseHsts();
                }

                app.UseSwagger()
                .UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Assessor Service API v1");
                })
                .UseAuthentication();

                if (UseSandbox)
                {
                    app.UseMiddleware <SandboxHeadersMiddleware>();
                }

                app.UseMiddleware <GetHeadersMiddleware>();

                app.UseHttpsRedirection();
                app.UseSecurityHeaders().UseMvc();
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error during Startup Configure");
                throw;
            }
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => false; // Default is true, make it false
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            ApplicationConfiguration = ConfigurationService.GetConfig(Configuration["EnvironmentName"], Configuration["ConfigurationStorageConnectionString"], Version, ServiceName).Result;

            services.AddHttpClient <ApiClient>("ApiClient", config =>
            {
                config.BaseAddress = new Uri(ApplicationConfiguration.EpaoApiAuthentication.ApiBaseAddress);
                config.DefaultRequestHeaders.Add("Accept", "Application/json");
            })
            .SetHandlerLifetime(TimeSpan.FromMinutes(5))      //Set lifetime to five minutes
            .AddPolicyHandler(GetRetryPolicy());

            services.AddHttpClient <ApplicationApiClient>("ApplicationApiClient", config =>
            {
                config.BaseAddress = new Uri(ApplicationConfiguration.EpaoApiAuthentication.ApiBaseAddress);
                config.DefaultRequestHeaders.Add("Accept", "Application/json");
            })
            .SetHandlerLifetime(TimeSpan.FromMinutes(5))      //Set lifetime to five minutes
            .AddPolicyHandler(GetRetryPolicy());

            AddAuthentication(services);

            services.Configure <RequestLocalizationOptions>(options =>
            {
                options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en-GB");
                options.SupportedCultures     = new List <CultureInfo> {
                    new CultureInfo("en-GB")
                };
                options.RequestCultureProviders.Clear();
            });

            services.AddMvc(options =>
            {
                options.Filters.Add <CheckSessionFilter>();
                options.Filters.Add <FeatureToggleFilter>();
                options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
                options.ModelBinderProviders.Insert(0, new SuppressBindingErrorsModelBinderProvider());
            })
            .AddMvcOptions(m => m.ModelMetadataDetailsProviders.Add(new HumanizerMetadataProvider()))
            .AddFluentValidation(fvc => fvc.RegisterValidatorsFromAssemblyContaining <Startup>())
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddJsonOptions(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.ViewLocationFormats.Add("/Views/Application/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.ViewLocationFormats.Add("/Views/Application/{0}" + RazorViewEngine.ViewExtension);
            });

            services.AddSession(opt =>
            {
                opt.IdleTimeout = TimeSpan.FromHours(1);
            });

            if (!_env.IsDevelopment())
            {
                services.AddDistributedRedisCache(options =>
                {
                    options.Configuration = ApplicationConfiguration.SessionRedisConnectionString;
                });
            }

            services.AddAntiforgery(options => options.Cookie = new CookieBuilder()
            {
                Name = ".Assessors.Staff.AntiForgery", HttpOnly = false
            });
            services.AddHealthChecks();
            MappingStartup.AddMappings();

            ConfigureDependencyInjection(services);
        }
 public void GlobalSetup()
 {
     MappingStartup.AddMappings();
 }