Ejemplo n.º 1
0
        private static void RegisterRepositories(IServiceCollection services, IConfiguration configuration)
        {
            var mongoConnectionString = configuration.GetConnectionString("MongoDb");

            services.Configure <MongoDbConnectionDetails>(options =>
            {
                options.ConnectionString = mongoConnectionString;
            });

            MongoDbConventions.RegisterMongoConventions();

            services.AddTransient <MongoDbCollectionChecker>();

            //Repositories
            services.AddTransient <IVacancyRepository, MongoDbVacancyRepository>();
            services.AddTransient <IVacancyReviewRepository, MongoDbVacancyReviewRepository>();
            services.AddTransient <IUserRepository, MongoDbUserRepository>();
            services.AddTransient <IApplicationReviewRepository, MongoDbApplicationReviewRepository>();
            services.AddTransient <IEmployerProfileRepository, MongoDbEmployerProfileRepository>();
            services.AddTransient <IReportRepository, MongoDbReportRepository>();
            services.AddTransient <IUserNotificationPreferencesRepository, MongoDbUserNotificationPreferencesRepository>();
            services.AddTransient <IBlockedOrganisationRepository, MongoDbBlockedOrganisationRepository>();

            //Queries
            services.AddTransient <IVacancyQuery, MongoDbVacancyRepository>();
            services.AddTransient <IVacancyReviewQuery, MongoDbVacancyReviewRepository>();
            services.AddTransient <IApplicationReviewQuery, MongoDbApplicationReviewRepository>();
            services.AddTransient <IBlockedOrganisationQuery, MongoDbBlockedOrganisationRepository>();

            services.AddTransient <IQueryStoreReader, QueryStoreClient>();
            services.AddTransient <IQueryStoreWriter, QueryStoreClient>();

            services.AddTransient <IReferenceDataReader, MongoDbReferenceDataRepository>();
            services.AddTransient <IReferenceDataWriter, MongoDbReferenceDataRepository>();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));
            services.Configure <RecruitConfiguration>(Configuration.GetSection("Recruit"));
            services.Configure <AzureActiveDirectoryConfiguration>(Configuration.GetSection("AzureAd"));

            var azureAdConfig = Configuration
                                .GetSection("AzureAd")
                                .Get <AzureActiveDirectoryConfiguration>();

            var policies = new Dictionary <string, string>
            {
                { PolicyNames.Default, "Default" },
            };

            services.AddAuthentication(azureAdConfig, policies);

            services.AddMediatR(typeof(Startup).Assembly, typeof(CreateApplicationReviewCommand).Assembly);

            services.AddSingleton <IVacancySummaryMapper, VacancySummaryMapper>();
            services.AddSingleton <IQueryStoreReader, QueryStoreClient>();

            services.AddRecruitStorageClient(Configuration);

            MongoDbConventions.RegisterMongoConventions();

            services.AddHealthChecks()
            .AddMongoDb(Configuration.GetConnectionString("MongoDb"))
            .AddApplicationInsightsPublisher();

            services.AddApplicationInsightsTelemetry();

            services
            .AddMvc(o =>
            {
                if (HostingEnvironment.IsDevelopment() == false)
                {
                    o.Conventions.Add(new AuthorizeControllerModelConvention(new List <string>()));
                }
                o.Conventions.Add(new ApiExplorerGroupPerVersionConvention());
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.IgnoreNullValues = true;
            });

            services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "RecruitAPI", Version = "v1"
                });
            });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();
            services.Configure <RecruitConfiguration>(Configuration.GetSection("Recruit"));
            services.Configure <AzureActiveDirectoryConfiguration>(Configuration.GetSection("AzureAd"));

            var serviceProvider = services.BuildServiceProvider();
            var recruitConfig   = serviceProvider.GetService <IOptions <RecruitConfiguration> >();

            SetupAuthorization(services, serviceProvider);

            services.AddMediatR(typeof(Startup).Assembly);

            services.AddSingleton <IVacancySummaryMapper, VacancySummaryMapper>();
            services.AddSingleton <IQueryStoreReader, QueryStoreClient>();

            MongoDbConventions.RegisterMongoConventions();

            services.AddHealthChecks()
            .AddMongoDb(recruitConfig.Value.ConnectionString)
            .AddApplicationInsightsPublisher();

            services.AddApplicationInsightsTelemetry();

            services
            .AddMvc(o =>
            {
                if (HostingEnvironment.IsDevelopment() == false)
                {
                    o.Filters.Add(new AuthorizeFilter("default"));
                }
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options => {
                options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });
        }