Exemple #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddControllers();
            services.AddCustomCompression();
            services.AddResponseCaching();

            // TODO Support multiple types of database, control through appsettings
            services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
            services.AddADAuthentication(Configuration);

            // Only required while experimenting with server side pre-rendering
            services.AddCustomPrerenderServices();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry();
            services.AddADAuthentication(Configuration);
            services.AddMediatR(typeof(GetApprenticeshipFavouritesRequest).Assembly);

            var storageConnectionString = Configuration.GetSection("ConnectionStrings").Get <ConnectionStrings>().AzureStorage;

            services.AddHealthChecks()
            .AddAzureTableStorage(storageConnectionString, "table-storage-check")
            .AddCheck <FatApiHealthCheck>("fat-api-check");

            services.AddMvc(options => {
                if (!HostingEnvironment.IsDevelopment())
                {
                    options.Filters.Add(new AuthorizeFilter("default"));
                }
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddTransient <IEmployerAccountRepository, EmployerAccountApiRepository>();

            services.AddTransient <IFatRepository, FatApiRepository>();
            services.AddTransient <IStandardApiClient, StandardApiClient>(service => new StandardApiClient(Configuration.GetValue <string>("FatApiBaseUrl")));
            services.AddTransient <IFrameworkApiClient, FrameworkApiClient>(service => new FrameworkApiClient(Configuration.GetValue <string>("FatApiBaseUrl")));
            services.AddTransient <IProviderApiClient, ProviderApiClient>(service => new ProviderApiClient(Configuration.GetValue <string>("FatApiBaseUrl")));

            services.AddScoped <IFavouritesReadRepository, FatFavouritesTableStorageRepository>();
            services.AddScoped <IFavouritesWriteRepository, FatFavouritesTableStorageRepository>();
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Employer-Favourites-Api", Version = "v1"
                });
                c.AddSecurityDefinition("Bearer", new ApiKeyScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = "header",
                    Type        = "apiKey"
                });
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
                c.CustomSchemaIds(i => i.FullName);
            });
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddADAuthentication(Configuration);
            services.AddControllers(options =>
            {
                if (!Environment.IsDevelopment())
                {
                    options.Filters.Add(new AuthorizeFilter("default"));
                }
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Pensions-Regulator-Api", Version = "v1"
                });
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey,
                    Scheme      = "Bearer"
                });

                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        Array.Empty <string>()
                    }
                });
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            services.AddMediatR(typeof(GetOrganisationsByPayeRef).Assembly);
            services.AddTransient <IOrganisationRepository, SqlOrganisationRepository>();
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
        }