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 <OnProviderResultsSpecificationCleanup>(); builder.AddScoped <OnReIndexCalculationResults>(); builder.AddScoped <OnCalculationResultsCsvGeneration>(); builder.AddScoped <OnCalculationResultsCsvGenerationTimer>(); builder.AddScoped <OnMergeSpecificationInformationForProviderWithResults>(); builder.AddScoped <OnMergeSpecificationInformationForProviderWithResultsFailure>(); builder.AddScoped <OnDeleteCalculationResults>(); builder.AddScoped <OnDeleteCalculationResultsFailure>(); builder.AddScoped <OnSearchIndexWriterEventTrigger>(); builder.AddScoped <OnSearchIndexWriterEventTriggerFailure>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <ISpecificationsWithProviderResultsService, SpecificationsWithProviderResultsService>(); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddSingleton <IConfiguration>(config); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>(); builder.AddSingleton <IResultsService, ResultsService>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder.AddSingleton <IDeadletterService, DeadletterService>(); builder.AddSingleton <IProviderCalculationResultsReIndexerService, ProviderCalculationResultsReIndexerService>(); builder.AddTransient <ICsvUtils, CsvUtils>(); builder .AddTransient <IProviderResultsCsvGeneratorService, ProviderResultsCsvGeneratorService>() .AddTransient <IHealthChecker, ProviderResultsCsvGeneratorService>(); builder.AddTransient <IProviderResultsToCsvRowsTransformation, ProviderResultsToCsvRowsTransformation>(); builder.AddSingleton <IFileSystemAccess, FileSystemAccess>(); builder.AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>(); builder .AddSingleton <ISearchIndexWriterSettings, SearchIndexWriterSettings>((ctx) => { IConfigurationSection setttingConfig = config.GetSection("searchIndexWriterSettings"); return(new SearchIndexWriterSettings(setttingConfig)); }); builder.AddSingleton <CommonStorage.IBlobClient>(ctx => { CommonStorage.BlobStorageOptions options = new CommonStorage.BlobStorageOptions(); config.Bind("AzureStorageSettings", options); options.ContainerName = "calcresults"; CommonStorage.IBlobContainerRepository blobContainerRepository = new CommonStorage.BlobContainerRepository(options); return(new CommonStorage.BlobClient(blobContainerRepository)); }); builder.AddScoped <ISearchIndexProcessorFactory, SearchIndexProcessorFactory>(); builder.AddScoped <ISearchIndexDataReader <ProviderResultDataKey, ProviderResult>, ProviderCalculationResultsIndexDataReader>(); builder.AddScoped <ISearchIndexTrasformer <ProviderResult, ProviderCalculationResultsIndex>, ProviderCalculationResultsIndexTransformer>(); builder.AddScoped <ISearchIndexProcessor, ProviderCalculationResultsIndexProcessor>(); builder.AddScoped <ISearchIndexWriterService, SearchIndexWriterService>(); builder.AddCaching(config); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>((ctx) => { CosmosDbSettings calssDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calssDbSettings); calssDbSettings.ContainerName = "calculationresults"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calssDbSettings); EngineSettings engineSettings = ctx.GetService <EngineSettings>(); return(new CalculationResultsRepository(calcsCosmosRepostory, engineSettings)); }); builder.AddSingleton <IProviderSourceDatasetRepository, ProviderSourceDatasetRepository>((ctx) => { CosmosDbSettings provDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", provDbSettings); provDbSettings.ContainerName = "providerdatasets"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(provDbSettings); return(new ProviderSourceDatasetRepository(calcsCosmosRepostory)); }); builder .AddSingleton <IBlobClient, AzureStorage.BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "calcresults"; return(new AzureStorage.BlobClient(storageSettings)); }); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >(); builder.AddServiceBus(config, "results"); builder.AddCaching(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Results"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Results"); builder.AddLogging("CalculateFunding.Functions.Results"); builder.AddTelemetry(); builder.AddEngineSettings(config); builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddProvidersInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); MapperConfiguration resultsConfig = new MapperConfiguration(c => { c.AddProfile <ResultsMappingProfile>(); }); builder.AddSingleton(resultsConfig.CreateMapper()); builder.AddFeatureToggling(config); builder.AddSingleton <ICancellationTokenProvider, InactiveCancellationTokenProvider>(); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); ResiliencePolicies resultsResiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <IResultsResiliencePolicies>(resultsResiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }
private void RegisterComponents(IServiceCollection builder) { builder.AddSpecificationsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan) .AddCalculationsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddScoped <ISpecificationsWithProviderResultsService, SpecificationsWithProviderResultsService>(); builder.AddScoped <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>(); builder .AddSingleton <IResultsService, ResultsService>() .AddSingleton <IHealthChecker, ResultsService>(); builder .AddSingleton <IJobManagement, JobManagement>(); builder .AddSingleton <IProviderCalculationResultsSearchService, ProviderCalculationResultsSearchService>() .AddSingleton <IHealthChecker, ProviderCalculationResultsSearchService>(); builder.AddHttpCachingMvc(); string key = Configuration.GetValue <string>("specificationsClient:ApiKey"); builder.AddGraphInterServiceClient(Configuration); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>((ctx) => { CosmosDbSettings calssDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calssDbSettings); calssDbSettings.ContainerName = "calculationresults"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calssDbSettings); EngineSettings engineSettings = ctx.GetService <EngineSettings>(); return(new CalculationResultsRepository(calcsCosmosRepostory, engineSettings)); }); builder.AddSingleton <IProviderSourceDatasetRepository, ProviderSourceDatasetRepository>((ctx) => { CosmosDbSettings provDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", provDbSettings); provDbSettings.ContainerName = "providerdatasets"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(provDbSettings); return(new ProviderSourceDatasetRepository(calcsCosmosRepostory)); }); builder.AddSingleton <IProviderCalculationResultsReIndexerService, ProviderCalculationResultsReIndexerService>(); builder .AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "calcresultexports"; return(new BlobClient(storageSettings)); }); builder.AddSingleton <CommonStorage.IBlobClient>(ctx => { CommonStorage.BlobStorageOptions options = new CommonStorage.BlobStorageOptions(); Configuration.Bind("AzureStorageSettings", options); options.ContainerName = "calcresultexports"; CommonStorage.IBlobContainerRepository blobContainerRepository = new CommonStorage.BlobContainerRepository(options); return(new CommonStorage.BlobClient(blobContainerRepository)); }); builder.AddSearch(Configuration); builder .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >(); builder.AddServiceBus(Configuration); builder.AddCaching(Configuration); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Results"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Results"); builder.AddLogging("CalculateFunding.Api.Results"); builder.AddTelemetry(); builder.AddEngineSettings(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddPoliciesInterServiceClient(Configuration); MapperConfiguration resultsConfig = new MapperConfiguration(c => { c.AddProfile <ResultsMappingProfile>(); }); builder.AddSingleton(resultsConfig.CreateMapper()); builder.AddPolicySettings(Configuration); builder.AddHttpContextAccessor(); builder.AddFeatureToggling(Configuration); builder.AddSingleton <IResultsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies() { CalculationProviderResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderProfilingRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderCalculationResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), PublishedProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderChangesRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderCalculationResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHealthCheckMiddleware(); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Results Microservice API"); } }