public static IServiceCollection AddCalcsResiliencePolicies(this IServiceCollection serviceCollection)
        {
            serviceCollection.AddSingleton <ICalcsResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                return(new ResiliencePolicies
                {
                    CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy),
                    CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                    CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
                    JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                });
            });

            return(serviceCollection);
        }
Пример #2
0
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            builder
            .AddSingleton <OnNotificationEventTrigger>();

            builder
            .AddSingleton <INotificationService, NotificationService>();

            builder.AddFeatureToggling(config);

            builder.AddServiceBus(config);

            builder.AddApplicationInsights(config, "CalculateFunding.Functions.Notifications");
            builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Notifications");
            builder.AddLogging("CalculateFunding.Functions.Notifications");
            builder.AddTelemetry();

            builder.AddPolicySettings(config);

            builder.AddSingleton <INotificationsResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                return(new NotificationsResiliencePolicies
                {
                    MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
                });
            });

            return(builder.BuildServiceProvider());
        }
Пример #3
0
        private static CalculatorResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings)
        {
            BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

            CalculatorResiliencePolicies resiliencePolicies = new CalculatorResiliencePolicies()
            {
                ProviderResultsRepository        = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                ProviderSourceDatasetsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                CacheProvider          = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                Messenger              = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
                CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                JobsApiClient          = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy)
            };

            return(resiliencePolicies);
        }
Пример #4
0
        private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings)
        {
            BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

            return(new ResiliencePolicies
            {
                CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy),
                CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
                JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                DatasetsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy)
            });
        }
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            // These registrations of the functions themselves are just for the DebugQueue. Ideally we don't want these registered in production
            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                builder
                .AddSingleton <OnNotificationEventTrigger>();
            }

            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();

            builder
            .AddSingleton <INotificationService, NotificationService>();

            builder.AddFeatureToggling(config);

            builder.AddServiceBus(config, "notifications");

            builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Notifications");
            builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Notifications");
            builder.AddLogging("CalculateFunding.Functions.Notifications");
            builder.AddTelemetry();

            builder.AddPolicySettings(config);

            builder.AddSingleton <INotificationsResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                return(new NotificationsResiliencePolicies
                {
                    MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
                });
            });

            builder.AddScoped <IUserProfileProvider, UserProfileProvider>();

            return(builder.BuildServiceProvider());
        }
 private static ResiliencePolicies CreateResiliencePolicies(AsyncPolicy totalNetworkRequestsPolicy)
 {
     return(new ResiliencePolicies
     {
         CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
         CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy),
         CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
         CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
         SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
         MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
         JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         GraphApiClientPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
         CalcEngineApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
     });
 }
Пример #7
0
        public void RegisterComponents(IServiceCollection builder)
        {
            builder
            .AddSingleton <ICalculationsRepository, CalculationsRepository>();

            builder
            .AddSingleton <ICalculationService, CalculationService>()
            .AddSingleton <IHealthChecker, CalculationService>();

            builder
            .AddSingleton <ICalculationCodeReferenceUpdate, CalculationCodeReferenceUpdate>()
            .AddSingleton <ITokenChecker, TokenChecker>();

            builder
            .AddSingleton <ICalculationsSearchService, CalculationSearchService>()
            .AddSingleton <IHealthChecker, CalculationSearchService>();

            builder
            .AddSingleton <IValidator <Calculation>, CalculationModelValidator>();

            builder
            .AddSingleton <IPreviewService, PreviewService>()
            .AddSingleton <IHealthChecker, PreviewService>();

            builder
            .AddSingleton <ICompilerFactory, CompilerFactory>();

            builder
            .AddSingleton <CSharpCompiler>()
            .AddSingleton <VisualBasicCompiler>()
            .AddSingleton <VisualBasicSourceFileGenerator>();

            builder
            .AddSingleton <ISourceFileGeneratorProvider, SourceFileGeneratorProvider>();

            builder
            .AddSingleton <IValidator <PreviewRequest>, PreviewRequestModelValidator>();

            builder
            .AddSingleton <IProviderResultsRepository, ProviderResultsRepository>()
            .AddSingleton <IHealthChecker, ProviderResultsRepository>();

            builder
            .AddSingleton <ISpecificationRepository, SpecificationRepository>();

            builder
            .AddSingleton <IBuildProjectsService, BuildProjectsService>()
            .AddSingleton <IHealthChecker, BuildProjectsService>();

            builder
            .AddSingleton <IBuildProjectsRepository, BuildProjectsRepository>()
            .AddSingleton <IHealthChecker, BuildProjectsRepository>();

            builder
            .AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>();

            builder
            .AddSingleton <IDatasetRepository, DatasetRepository>();

            builder.AddSingleton <ISourceCodeService, SourceCodeService>();

            builder
            .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>();

            builder.AddSingleton <ISourceFileRepository, SourceFileRepository>((ctx) =>
            {
                BlobStorageOptions blobStorageOptions = new BlobStorageOptions();

                Configuration.Bind("CommonStorageSettings", blobStorageOptions);

                blobStorageOptions.ContainerName = "source";

                return(new SourceFileRepository(blobStorageOptions));
            });

            builder.AddSingleton <IVersionRepository <CalculationVersion>, VersionRepository <CalculationVersion> >((ctx) =>
            {
                CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", calcsVersioningDbSettings);

                calcsVersioningDbSettings.CollectionName = "calcs";

                CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings);

                return(new VersionRepository <CalculationVersion>(resultsRepostory));
            });

            builder
            .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>();

            builder.AddUserProviderFromRequest();

            builder.AddCosmosDb(Configuration);

            builder.AddSearch(Configuration);

            builder.AddServiceBus(Configuration);

            builder.AddResultsInterServiceClient(Configuration);
            builder.AddSpecificationsInterServiceClient(Configuration);
            builder.AddDatasetsInterServiceClient(Configuration);
            builder.AddJobsInterServiceClient(Configuration);

            builder.AddCaching(Configuration);

            builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Calcs");
            builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Calcs");
            builder.AddLogging("CalculateFunding.Api.Calcs");
            builder.AddTelemetry();

            builder.AddEngineSettings(Configuration);

            builder.AddFeatureToggling(Configuration);

            builder.AddPolicySettings(Configuration);

            builder.AddSingleton <ICalcsResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                return(new ResiliencePolicies
                {
                    CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy),
                    CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                    CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
                    JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    DatasetsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy)
                });
            });

            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            builder.AddHttpContextAccessor();

            builder.AddHealthCheckMiddleware();
        }
Пример #8
0
        public void RegisterComponents(IServiceCollection builder)
        {
            builder
            .AddSingleton <IJobDefinitionsService, JobDefinitionsService>()
            .AddSingleton <IHealthChecker, JobDefinitionsService>();

            builder
            .AddSingleton <IJobService, JobService>()
            .AddSingleton <IHealthChecker, JobService>();

            builder
            .AddSingleton <INotificationService, NotificationService>();

            builder
            .AddSingleton <IJobManagementService, JobManagementService>()
            .AddSingleton <IHealthChecker, JobManagementService>();

            builder.
            AddSingleton <IValidator <CreateJobValidationModel>, CreateJobValidator>();

            builder
            .AddSingleton <IJobDefinitionsRepository, JobDefinitionsRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobdefinitions";

                CosmosRepository jobDefinitionsCosmosRepostory = new CosmosRepository(cosmosDbSettings);

                return(new JobDefinitionsRepository(jobDefinitionsCosmosRepostory));
            });

            builder
            .AddSingleton <IJobRepository, JobRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobs";

                CosmosRepository jobCosmosRepostory = new CosmosRepository(cosmosDbSettings);

                return(new JobRepository(jobCosmosRepostory));
            });

            MapperConfiguration mappingConfig = new MapperConfiguration(c => c.AddProfile <JobsMappingProfile>());

            builder.AddSingleton(mappingConfig.CreateMapper());

            builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Jobs");
            builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Jobs");
            builder.AddLogging("CalculateFunding.Api.Jobs");
            builder.AddTelemetry();

            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            builder.AddPolicySettings(Configuration);

            builder.AddCaching(Configuration);

            builder.AddServiceBus(Configuration);

            builder.AddSingleton <IJobsResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                BulkheadPolicy totalNetworkRequestsPolicy         = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);
                BulkheadPolicy totalNetworkRequestsPolicyNonAsync = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsNonAsyncPolicy(policySettings);
                return(new ResiliencePolicies
                {
                    JobDefinitionsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                    JobRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    JobRepositoryNonAsync = CosmosResiliencePolicyHelper.GenerateNonAsyncCosmosPolicy(totalNetworkRequestsPolicyNonAsync),
                    MessengerServicePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy)
                });
            });

            builder.AddHealthCheckMiddleware();
        }
Пример #9
0
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            builder
            .AddSingleton <OnJobNotification>();

            builder
            .AddSingleton <OnCheckForJobTimeout>();

            builder
            .AddSingleton <IJobManagementService, JobManagementService>();

            builder.
            AddSingleton <IValidator <CreateJobValidationModel>, CreateJobValidator>();

            builder
            .AddSingleton <IJobRepository, JobRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobs";

                CosmosRepository jobCosmosRepostory = new CosmosRepository(cosmosDbSettings);

                return(new JobRepository(jobCosmosRepostory));
            });

            builder
            .AddSingleton <INotificationService, NotificationService>();

            builder
            .AddSingleton <IJobDefinitionsService, JobDefinitionsService>();

            builder
            .AddSingleton <IJobDefinitionsRepository, JobDefinitionsRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobdefinitions";

                CosmosRepository jobDefinitionsCosmosRepostory = new CosmosRepository(cosmosDbSettings);

                return(new JobDefinitionsRepository(jobDefinitionsCosmosRepostory));
            });

            builder.AddServiceBus(config);

            builder.AddPolicySettings(config);

            builder.AddCaching(config);

            builder.AddSingleton <IJobsResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                BulkheadPolicy totalNetworkRequestsPolicy         = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);
                BulkheadPolicy totalNetworkRequestsPolicyNonAsync = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsNonAsyncPolicy(policySettings);

                return(new ResiliencePolicies
                {
                    JobDefinitionsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                    JobRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    JobRepositoryNonAsync = CosmosResiliencePolicyHelper.GenerateNonAsyncCosmosPolicy(totalNetworkRequestsPolicyNonAsync),
                    MessengerServicePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy)
                });
            });

            builder.AddApplicationInsights(config, "CalculateFunding.Functions.Jobs");
            builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Jobs");

            builder.AddLogging("CalculateFunding.Functions.Jobs");

            builder.AddTelemetry();

            return(builder.BuildServiceProvider());
        }
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            // These registrations of the functions themselves are just for the DebugQueue. Ideally we don't want these registered in production
            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                builder.AddScoped <OnJobNotification>();
                builder.AddScoped <OnCheckForJobTimeout>();
            }

            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();

            builder.AddSingleton <IJobManagementService, JobManagementService>();

            builder
            .AddSingleton <IValidator <JobDefinition>, JobDefinitionValidator>();

            builder.
            AddSingleton <IValidator <CreateJobValidationModel>, CreateJobValidator>();

            builder
            .AddSingleton <IJobRepository, JobRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "jobs";

                CosmosRepository jobCosmosRepostory = new CosmosRepository(cosmosDbSettings);

                return(new JobRepository(jobCosmosRepostory));
            });

            builder
            .AddSingleton <INotificationService, NotificationService>();

            builder
            .AddSingleton <IJobDefinitionsService, JobDefinitionsService>();

            builder
            .AddSingleton <IJobDefinitionsRepository, JobDefinitionsRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "jobdefinitions";

                CosmosRepository jobDefinitionsCosmosRepostory = new CosmosRepository(cosmosDbSettings);

                return(new JobDefinitionsRepository(jobDefinitionsCosmosRepostory));
            });

            builder.AddServiceBus(config, "jobs");

            builder.AddPolicySettings(config);

            builder.AddCaching(config);

            builder.AddSingleton <IJobsResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                AsyncBulkheadPolicy totalNetworkRequestsPolicy    = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);
                BulkheadPolicy totalNetworkRequestsPolicyNonAsync = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsNonAsyncPolicy(policySettings);

                return(new ResiliencePolicies
                {
                    JobDefinitionsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                    JobRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    MessengerServicePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy)
                });
            });

            builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Jobs");
            builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Jobs");

            builder.AddLogging("CalculateFunding.Functions.Jobs");

            builder.AddTelemetry();

            builder.AddScoped <IUserProfileProvider, UserProfileProvider>();

            return(builder.BuildServiceProvider());
        }