public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); builder.AddSingleton <ICosmosDbScalingService, CosmosDbScalingService>(); builder.AddSingleton <ICosmosDbScalingRepositoryProvider, CosmosDbScalingRepositoryProvider>(); builder.AddSingleton <ICosmosDbScalingRequestModelBuilder, CosmosDbScalingRequestModelBuilder>(); builder.AddSingleton <ICosmosDbThrottledEventsFilter, CosmosDbThrottledEventsFilter>(); builder.AddSingleton <IValidator <ScalingConfigurationUpdateModel>, ScalingConfigurationUpdateModelValidator>(); builder.AddSingleton <ICosmosDbScalingConfigRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "cosmosscalingconfig"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new CosmosDbScalingConfigRepository(cosmosRepository)); }); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddFeatureToggling(Configuration); builder.AddServiceBus(Configuration); builder.AddSearch(Configuration); builder.AddCaching(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); builder.AddSingleton <ICosmosDbScalingResiliencePolicies>(m => { PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); CosmosDbScalingResiliencePolicies resiliencePolicies = new CosmosDbScalingResiliencePolicies() { ScalingRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ScalingConfigRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Apis.CosmosDbScaling"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.CosmosDbScaling"); builder.AddLogging("CalculateFunding.Apis.CosmosDbScaling"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "CosmosDbScaling Microservice API", version: "v1"); } }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <IValidator <SetFundingStreamCurrentProviderVersionRequest>, SetFundingStreamCurrentProviderVersionRequestValidator>(); builder.AddSingleton <IFundingStreamProviderVersionService, FundingStreamProviderVersionService>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder.AddCaching(Configuration); builder .AddSingleton <IProviderVersionService, ProviderVersionService>() .AddSingleton <IHealthChecker, ProviderVersionService>(); builder .AddSingleton <IProviderVersionSearchService, ProviderVersionSearchService>() .AddSingleton <IHealthChecker, ProviderVersionSearchService>(); builder .AddSingleton <IJobManagement, JobManagement>(); builder .AddSingleton <IScopedProvidersService, ScopedProvidersService>() .AddSingleton <IHealthChecker, ScopedProvidersService>(); builder .AddSingleton <IProviderVersionUpdateCheckService, ProviderVersionUpdateCheckService>(); builder.AddSingleton <IValidator <ProviderVersionViewModel>, UploadProviderVersionValidator>(); builder.AddSearch(this.Configuration); builder .AddSingleton <ISearchRepository <ProvidersIndex>, SearchRepository <ProvidersIndex> >(); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "providerversions"; return(new BlobClient(storageSettings)); }); builder.AddSingleton <IProviderVersionsMetadataRepository, ProviderVersionsMetadataRepository>( ctx => { CosmosDbSettings specRepoDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", specRepoDbSettings); specRepoDbSettings.ContainerName = "providerversionsmetadata"; CosmosRepository cosmosRepository = new CosmosRepository(specRepoDbSettings); return(new ProviderVersionsMetadataRepository(cosmosRepository)); }); builder.AddPolicySettings(Configuration); MapperConfiguration providerVersionsConfig = new MapperConfiguration(c => { c.AddProfile <ProviderVersionsMappingProfile>(); }); builder .AddSingleton(providerVersionsConfig.CreateMapper()); builder.AddPoliciesInterServiceClient(Configuration); builder.AddResultsInterServiceClient(Configuration); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Providers"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Providers"); builder.AddLogging("CalculateFunding.Api.Providers"); builder.AddTelemetry(); builder.AddServiceBus(Configuration); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ProvidersResiliencePolicies resiliencePolicies = CreateResiliencePolicies(totalNetworkRequestsPolicy); builder.AddSingleton <IJobManagementResiliencePolicies>(resiliencePolicies); builder.AddSingleton <IProvidersResiliencePolicies>(resiliencePolicies); builder .AddSingleton <IFileSystemCache, FileSystemCache>() .AddSingleton <IFileSystemAccess, FileSystemAccess>() .AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>(); builder .AddSingleton <IProviderVersionServiceSettings>(ctx => { ProviderVersionServiceSettings settings = new ProviderVersionServiceSettings(); Configuration.Bind("providerversionservicesettings", settings); return(settings); }); builder .AddSingleton <IScopedProvidersServiceSettings>(ctx => { ScopedProvidersServiceSettings settings = new ScopedProvidersServiceSettings(); Configuration.Bind("scopedprovidersservicesetting", settings); return(settings); }); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHealthCheckMiddleware(); builder.AddHttpContextAccessor(); builder.AddSearch(Configuration); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Provider Microservice API"); } }
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()); }
public void RegisterComponents(IServiceCollection builder) { builder.AddHttpCachingMvc(); builder.AddQueryProviderAndExtractorForViewModelMvc < FundingStructure, TemplateMetadataContentsTimedETagProvider, TemplateMatadataContentsTimedETagExtractor>(false); builder.AddSingleton <IFundingStructureService, FundingStructureService>() .AddSingleton <IValidator <UpdateFundingStructureLastModifiedRequest>, UpdateFundingStructureLastModifiedRequestValidator>(); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder.AddSingleton <IQueueCreateSpecificationJobActions, QueueCreateSpecificationJobAction>(); builder.AddSingleton <IQueueEditSpecificationJobActions, QueueEditSpecificationJobActions>(); builder.AddSingleton <IQueueDeleteSpecificationJobActions, QueueDeleteSpecificationJobAction>(); builder.AddSingleton <ISpecificationsRepository, SpecificationsRepository>((ctx) => { CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", specsVersioningDbSettings); specsVersioningDbSettings.ContainerName = "specs"; CosmosRepository resultsRepostory = new CosmosRepository(specsVersioningDbSettings); return(new SpecificationsRepository(resultsRepostory)); }); builder .AddSingleton <ISpecificationsService, SpecificationsService>() .AddSingleton <IHealthChecker, SpecificationsService>(); builder.AddSingleton <ISpecificationIndexer, SpecificationIndexer>(); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddSingleton <ISpecificationIndexingService, SpecificationIndexingService>(); builder .AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <IValidator <SpecificationCreateModel>, SpecificationCreateModelValidator>(); builder.AddSingleton <IValidator <SpecificationEditModel>, SpecificationEditModelValidator>(); builder.AddSingleton <IValidator <AssignDefinitionRelationshipMessage>, AssignDefinitionRelationshipMessageValidator>(); builder.AddSingleton <IValidator <AssignSpecificationProviderVersionModel>, AssignSpecificationProviderVersionModelValidator>(); builder .AddSingleton <ISpecificationsSearchService, SpecificationsSearchService>() .AddSingleton <IHealthChecker, SpecificationsSearchService>(); builder.AddSingleton <IResultsRepository, ResultsRepository>(); builder .AddSingleton <ISpecificationsReportService, SpecificationsReportService>() .AddSingleton <IHealthChecker, SpecificationsReportService>(); builder.AddSingleton <ITemplateMetadataResolver>((ctx) => { TemplateMetadataResolver resolver = new TemplateMetadataResolver(); TemplateMetadataGenerator schema10Generator = new TemplateMetadataGenerator(ctx.GetService <ILogger>()); resolver.Register("1.0", schema10Generator); return(resolver); }); builder .AddSingleton <LocalIBlobClient, LocalBlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "providerversions"; return(new LocalBlobClient(storageSettings)); }); builder.AddSingleton <ISpecificationTemplateVersionChangedHandler, SpecificationTemplateVersionChangedHandler>(); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { BlobStorageOptions storageSettings = new BlobStorageOptions(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "providerversions"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(storageSettings); return(new BlobClient(blobContainerRepository)); }); builder.AddSingleton <IVersionRepository <Models.Specs.SpecificationVersion>, VersionRepository <Models.Specs.SpecificationVersion> >((ctx) => { CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", specsVersioningDbSettings); specsVersioningDbSettings.ContainerName = "specs"; CosmosRepository resultsRepostory = new CosmosRepository(specsVersioningDbSettings); return(new VersionRepository <Models.Specs.SpecificationVersion>(resultsRepostory, new NewVersionBuilderFactory <SpecificationVersion>())); }); MapperConfiguration mappingConfig = new MapperConfiguration( c => { c.AddProfile <SpecificationsMappingProfile>(); } ); builder.AddFeatureToggling(Configuration); builder.AddSingleton(mappingConfig.CreateMapper()); builder.AddServiceBus(Configuration); builder.AddSearch(Configuration); builder .AddSingleton <ISearchRepository <SpecificationIndex>, SearchRepository <SpecificationIndex> >(); builder.AddCaching(Configuration); builder.AddResultsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddGraphInterServiceClient(Configuration); builder.AddCalculationsInterServiceClient(Configuration); builder.AddProvidersInterServiceClient(Configuration); builder.AddPoliciesInterServiceClient(Configuration); builder.AddDatasetsInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); builder.AddSingleton <ISpecificationsResiliencePolicies>((ctx) => { Polly.AsyncPolicy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new SpecificationsResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalcsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsSearchRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }); }); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Apis.Specs"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Specs"); builder.AddLogging("CalculateFunding.Apis.Specs"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Specs Microservice API"); } }
public void RegisterComponents(IServiceCollection builder) { builder.AddScoped <ICalculationEngineService, CalculationEngineService>(); builder.AddScoped <ICalculationEngine, CalculationEngine>(); builder.AddScoped <IAllocationFactory, AllocationFactory>(); builder.AddScoped <IJobManagement, JobManagement>(); builder.AddSingleton <IProviderSourceDatasetVersionKeyProvider, ProviderSourceDatasetVersionKeyProvider>(); builder.AddSingleton <IFileSystemAccess, FileSystemAccess>(); builder.AddSingleton <IAssemblyService, AssemblyService>(); builder.AddSingleton <ICalculationAggregationService, CalculationAggregationService>(); builder.AddScoped <ICalculationEnginePreviewService, CalculationEnginePreviewService>(); builder.AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>(); builder.AddSingleton <IFileSystemCache, FileSystemCache>(); builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>((ctx) => { CosmosDbSettings providerSourceDatasetsCosmosSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", providerSourceDatasetsCosmosSettings); providerSourceDatasetsCosmosSettings.ContainerName = "providerdatasets"; CosmosRepository calcsCosmosRepository = new CosmosRepository(providerSourceDatasetsCosmosSettings, new CosmosClientOptions() { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = 8, MaxTcpConnectionsPerEndpoint = 4, ConsistencyLevel = ConsistencyLevel.Eventual, AllowBulkExecution = true, }); ICalculatorResiliencePolicies calculatorResiliencePolicies = ctx.GetService <ICalculatorResiliencePolicies>(); return(new ProviderSourceDatasetsRepository(calcsCosmosRepository, calculatorResiliencePolicies)); }); builder.AddSingleton <IProviderResultCalculationsHashProvider, ProviderResultCalculationsHashProvider>(); builder.AddSingleton <IProviderResultsRepository, ProviderResultsRepository>((ctx) => { CosmosDbSettings calcResultsDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calcResultsDbSettings); calcResultsDbSettings.ContainerName = "calculationresults"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calcResultsDbSettings, new CosmosClientOptions() { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = 8, MaxTcpConnectionsPerEndpoint = 2, // MaxRetryWaitTimeOnRateLimitedRequests = new TimeSpan(0, 0, 30), AllowBulkExecution = true, }); ILogger logger = ctx.GetService <ILogger>(); IProviderResultCalculationsHashProvider calculationsHashProvider = ctx.GetService <IProviderResultCalculationsHashProvider>(); ICalculatorResiliencePolicies calculatorResiliencePolicies = ctx.GetService <ICalculatorResiliencePolicies>(); IResultsApiClient resultsApiClient = ctx.GetService <IResultsApiClient>(); IJobManagement jobManagement = ctx.GetService <IJobManagement>(); return(new ProviderResultsRepository( calcsCosmosRepostory, logger, calculationsHashProvider, calculatorResiliencePolicies, resultsApiClient, jobManagement)); }); builder .AddSingleton <IBlobContainerRepository, BlobContainerRepository>(); builder .AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder .AddSingleton <IDatasetAggregationsRepository, DatasetAggregationsRepository>(); builder .AddSingleton <ICancellationTokenProvider, InactiveCancellationTokenProvider>(); MapperConfiguration calculationsConfig = new MapperConfiguration(c => { c.AddProfile <CalculationsMappingProfile>(); c.AddProfile <CalcEngineMappingProfile>(); }); builder .AddSingleton(calculationsConfig.CreateMapper()); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddCalculationsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSpecificationsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddJobsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddResultsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddDatasetsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddProvidersInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddEngineSettings(Configuration); builder.AddServiceBus(Configuration, "calcengine"); builder.AddCaching(Configuration); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.CalcEngine"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.CalcEngine"); builder.AddLogging("CalculateFunding.Api.CalcEngine"); builder.AddTelemetry(); builder.AddSearch(Configuration); builder .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >(); builder.AddFeatureToggling(Configuration); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration); CalculatorResiliencePolicies calcResiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <ICalculatorResiliencePolicies>(calcResiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => new JobManagementResiliencePolicies() { JobsApiClient = calcResiliencePolicies.JobsApiClient }); builder.AddSingleton <IValidator <ICalculatorResiliencePolicies>, CalculatorResiliencePoliciesValidator>(); builder.AddSingleton <ICalculationEngineServiceValidator, CalculationEngineServiceValidator>(); builder.AddSingleton <ISpecificationAssemblyProvider, SpecificationAssemblyProvider>(); builder.AddSingleton <IBlobClient>(ctx => { BlobStorageOptions options = new BlobStorageOptions(); Configuration.Bind("AzureStorageSettings", options); options.ContainerName = "source"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(options); return(new BlobClient(blobContainerRepository)); }); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "CalcEngine Microservice API", version: "v1"); } }
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 <OnPopulateScopedProvidersEventTrigger>(); builder.AddScoped <OnPopulateScopedProvidersEventTriggerFailure>(); builder.AddScoped <OnProviderSnapshotDataLoadEventTrigger>(); builder.AddScoped <OnProviderSnapshotDataLoadEventTriggerFailure>(); builder.AddScoped <OnNewProviderVersionCheck>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <IConfiguration>(config); builder .AddSingleton <IProviderVersionService, ProviderVersionService>() .AddSingleton <IHealthChecker, ProviderVersionService>(); builder .AddSingleton <IProviderSnapshotDataLoadService, ProviderSnapshotDataLoadService>() .AddSingleton <IHealthChecker, ProviderSnapshotDataLoadService>(); builder .AddSingleton <IScopedProvidersService, ScopedProvidersService>() .AddSingleton <IHealthChecker, ScopedProvidersService>(); builder .AddSingleton <IProviderVersionUpdateCheckService, ProviderVersionUpdateCheckService>(); builder .AddSingleton <IProvidersApiClient, ProvidersApiClient>(); builder .AddSingleton <IJobManagement, JobManagement>(); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddResultsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddFundingDataServiceInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSingleton <IDeadletterService, DeadletterService>(); builder.AddCaching(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Providers"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Providers"); builder.AddLogging("CalculateFunding.Functions.Providers"); builder.AddTelemetry(); builder.AddFeatureToggling(config); MapperConfiguration providerVersionsConfig = new MapperConfiguration(c => { c.AddProfile <ProviderVersionsMappingProfile>(); }); builder .AddSingleton(providerVersionsConfig.CreateMapper()); builder .AddSingleton <IFileSystemCache, FileSystemCache>() .AddSingleton <IFileSystemAccess, FileSystemAccess>() .AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>(); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <ProvidersIndex>, SearchRepository <ProvidersIndex> >(); builder .AddSingleton <IProviderVersionServiceSettings>(ctx => { ProviderVersionServiceSettings settings = new ProviderVersionServiceSettings(); config.Bind("providerversionservicesettings", settings); return(settings); }); builder .AddSingleton <IScopedProvidersServiceSettings>(ctx => { ScopedProvidersServiceSettings settings = new ScopedProvidersServiceSettings(); config.Bind("scopedprovidersservicesetting", settings); return(settings); }); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ProvidersResiliencePolicies resiliencePolicies = CreateResiliencePolicies(totalNetworkRequestsPolicy); builder.AddSingleton <IJobManagementResiliencePolicies>(resiliencePolicies); builder.AddSingleton <IProvidersResiliencePolicies>(resiliencePolicies); builder.AddSingleton <IValidator <ProviderVersionViewModel>, UploadProviderVersionValidator>(); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "providerversions"; return(new BlobClient(storageSettings)); }); builder.AddSingleton <IProviderVersionsMetadataRepository, ProviderVersionsMetadataRepository>( ctx => { CosmosDbSettings specRepoDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", specRepoDbSettings); specRepoDbSettings.ContainerName = "providerversionsmetadata"; CosmosRepository cosmosRepository = new CosmosRepository(specRepoDbSettings); return(new ProviderVersionsMetadataRepository(cosmosRepository)); }); builder.AddServiceBus(config, "providers"); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <ISpecificationTemplateVersionChangedHandler, SpecificationTemplateVersionChangedHandler>(); builder.AddSingleton <IQueueCreateSpecificationJobActions, QueueCreateSpecificationJobAction>(); builder.AddSingleton <IQueueEditSpecificationJobActions, QueueEditSpecificationJobActions>(); builder.AddSingleton <IQueueDeleteSpecificationJobActions, QueueDeleteSpecificationJobAction>(); // 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 <OnAddRelationshipEvent>(); builder.AddScoped <OnReIndexSpecification>(); builder.AddScoped <OnDeleteSpecifications>(); builder.AddScoped <OnDeleteSpecificationsFailure>(); } builder.AddSingleton <ISpecificationsRepository, SpecificationsRepository>((ctx) => { CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", specsVersioningDbSettings); specsVersioningDbSettings.ContainerName = "specs"; CosmosRepository resultsRepository = new CosmosRepository(specsVersioningDbSettings); return(new SpecificationsRepository(resultsRepository)); }); builder.AddSingleton <ISpecificationsService, SpecificationsService>(); builder.AddSingleton <IValidator <SpecificationCreateModel>, SpecificationCreateModelValidator>(); builder.AddSingleton <IValidator <SpecificationEditModel>, SpecificationEditModelValidator>(); builder.AddSingleton <IValidator <AssignDefinitionRelationshipMessage>, AssignDefinitionRelationshipMessageValidator>(); builder.AddSingleton <IValidator <AssignSpecificationProviderVersionModel>, AssignSpecificationProviderVersionModelValidator>(); builder.AddSingleton <ISpecificationsSearchService, SpecificationsSearchService>(); builder.AddSingleton <IResultsRepository, ResultsRepository>(); builder.AddSingleton <ISpecificationIndexer, SpecificationIndexer>(); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddSingleton <ISpecificationIndexingService, SpecificationIndexingService>(); builder.AddSingleton <IDeadletterService, DeadletterService>(); builder.AddSingleton <ITemplateMetadataResolver>((ctx) => { TemplateMetadataResolver resolver = new TemplateMetadataResolver(); TemplateMetadataGenerator schema10Generator = new TemplateMetadataGenerator(ctx.GetService <ILogger>()); resolver.Register("1.0", schema10Generator); return(resolver); }); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "providerversions"; return(new BlobClient(storageSettings)); }); builder.AddSingleton <IVersionRepository <Models.Specs.SpecificationVersion>, VersionRepository <Models.Specs.SpecificationVersion> >((ctx) => { CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", specsVersioningDbSettings); specsVersioningDbSettings.ContainerName = "specs"; CosmosRepository cosmosRepository = new CosmosRepository(specsVersioningDbSettings); return(new VersionRepository <Models.Specs.SpecificationVersion>(cosmosRepository, new NewVersionBuilderFactory <SpecificationVersion>())); }); builder .AddSingleton <IJobManagement, JobManagement>(); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); builder.AddSingleton <ISpecificationsResiliencePolicies>((ctx) => { Polly.AsyncPolicy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new SpecificationsResiliencePolicies() { PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalcsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsSearchRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }); }); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); MapperConfiguration mappingConfig = new MapperConfiguration(c => { c.AddProfile <SpecificationsMappingProfile>(); }); builder.AddSingleton(mappingConfig.CreateMapper()); builder.AddServiceBus(config, "specs"); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <SpecificationIndex>, SearchRepository <SpecificationIndex> >(); builder.AddCaching(config); builder.AddResultsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddProvidersInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddDatasetsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPolicySettings(config); builder.AddFeatureToggling(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Specs"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Specs"); builder.AddLogging("CalculateFunding.Functions.Specs"); builder.AddTelemetry(); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddFeatureManagement(); builder.AddSingleton <IConfiguration>(ctx => 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 <CalcsAddRelationshipToBuildProject>(); builder.AddScoped <OnCalcsInstructAllocationResultsFailure>(); builder.AddScoped <OnCalcsInstructAllocationResults>(); builder.AddScoped <OnCalculationAggregationsJobCompleted>(); builder.AddScoped <OnDataDefinitionChanges>(); builder.AddScoped <OnApplyTemplateCalculations>(); builder.AddScoped <OnApplyTemplateCalculationsFailure>(); builder.AddScoped <OnReIndexSpecificationCalculationRelationships>(); builder.AddScoped <OnReIndexSpecificationCalculationRelationshipsFailure>(); builder.AddScoped <OnDeleteCalculations>(); builder.AddScoped <OnDeleteCalculationsFailure>(); builder.AddScoped <OnUpdateCodeContextCache>(); builder.AddScoped <OnUpdateCodeContextCacheFailure>(); builder.AddScoped <OnApproveAllCalculations>(); builder.AddScoped <OnApproveAllCalculationsFailure>(); } builder.AddSingleton <IFundingLineRoundingSettings, FundingLineRoundingSettings>(); builder.AddScoped <IApplyTemplateCalculationsService, ApplyTemplateCalculationsService>(); builder.AddSingleton <ICalculationsRepository, CalculationsRepository>((ctx) => { CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calcsVersioningDbSettings); calcsVersioningDbSettings.ContainerName = "calcs"; CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings); return(new CalculationsRepository(resultsRepostory)); }); builder.AddScoped <ICalculationService, CalculationService>() .AddScoped <IInstructionAllocationJobCreation, InstructionAllocationJobCreation>() .AddScoped <ICreateCalculationService, CreateCalculationService>(); builder.AddSingleton <ICalculationNameInUseCheck, CalculationNameInUseCheck>(); builder.AddSingleton <ICalculationsSearchService, CalculationSearchService>(); builder.AddSingleton <ICalculationCodeReferenceUpdate, CalculationCodeReferenceUpdate>(); builder.AddSingleton <IValidator <Calculation>, CalculationModelValidator>(); builder.AddScoped <IPreviewService, PreviewService>(); builder.AddSingleton <ICompilerFactory, CompilerFactory>(); //builder.AddSingleton<IDatasetRepository, DatasetRepository>(); builder.AddScoped <IJobService, JobService>(); builder.AddScoped <IApproveAllCalculationsJobAction, ApproveAllCalculationsJobAction>(); builder .AddSingleton <CSharpCompiler>() .AddSingleton <VisualBasicCompiler>() .AddSingleton <VisualBasicSourceFileGenerator>(); builder.AddSingleton <ISourceFileGeneratorProvider, SourceFileGeneratorProvider>(); builder.AddSingleton <IValidator <PreviewRequest>, PreviewRequestModelValidator>(); builder.AddScoped <IBuildProjectsService, BuildProjectsService>(); builder.AddSingleton <IBuildProjectsRepository, BuildProjectsRepository>((ctx) => { CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calcsVersioningDbSettings); calcsVersioningDbSettings.ContainerName = "calcs"; CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings); return(new BuildProjectsRepository(resultsRepostory)); }); builder.AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>(); builder.AddSingleton <ICancellationTokenProvider, InactiveCancellationTokenProvider>(); builder.AddSingleton <ISourceCodeService, SourceCodeService>(); builder.AddScoped <IDeadletterService, DeadletterService>(); builder.AddScoped <IJobManagement, JobManagement>(); MapperConfiguration calculationsConfig = new MapperConfiguration(c => { c.AddProfile <CalculationsMappingProfile>(); }); builder .AddSingleton(calculationsConfig.CreateMapper()); builder.AddScoped <IReIndexGraphRepository, ReIndexGraphRepository>(); builder.AddScoped <ISpecificationCalculationAnalysis, SpecificationCalculationAnalysis>(); builder.AddScoped <IReIndexSpecificationCalculationRelationships, ReIndexSpecificationCalculationRelationships>(); builder.AddScoped <ICalculationAnalysis, CalculationAnalysis>(); builder .AddScoped <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); builder.AddScoped <ICalculationEngineRunningChecker, CalculationEngineRunningChecker>(); builder.AddScoped <IValidator <CalculationCreateModel>, CalculationCreateModelValidator>(); builder.AddScoped <IApproveAllCalculationsService, ApproveAllCalculationsService>(); builder .AddScoped <IDatasetReferenceService, DatasetReferenceService>(); builder .AddScoped <IValidator <CalculationEditModel>, CalculationEditModelValidator>(); builder.AddSingleton <ISourceFileRepository, SourceFileRepository>(ctx => { BlobStorageOptions blobStorageOptions = new BlobStorageOptions(); config.Bind("AzureStorageSettings", blobStorageOptions); blobStorageOptions.ContainerName = "source"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(blobStorageOptions); return(new SourceFileRepository(blobContainerRepository)); }); builder.AddSingleton <IVersionRepository <CalculationVersion>, VersionRepository <CalculationVersion> >((ctx) => { CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calcsVersioningDbSettings); calcsVersioningDbSettings.ContainerName = "calcs"; CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings); return(new VersionRepository <CalculationVersion>(resultsRepostory, new NewVersionBuilderFactory <CalculationVersion>())); }); builder.AddFeatureToggling(config); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <CalculationIndex>, SearchRepository <CalculationIndex> >(); builder .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >(); builder.AddServiceBus(config, "calcs"); builder.AddScoped <ICalculationsFeatureFlag, CalculationsFeatureFlag>(); builder.AddScoped <IGraphRepository, GraphRepository>(); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); builder.AddProvidersInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddDatasetsInterServiceClient(config); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddGraphInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddResultsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddCalcEngineInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddCaching(config); builder.AddEngineSettings(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Calcs"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Calcs"); builder.AddLogging("CalculateFunding.Functions.Calcs"); builder.AddTelemetry(); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ResiliencePolicies resiliencePolicies = CreateResiliencePolicies(totalNetworkRequestsPolicy); builder.AddSingleton <ICalcsResiliencePolicies>(resiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => new JobManagementResiliencePolicies() { JobsApiClient = resiliencePolicies.JobsApiClient, }); builder.AddScoped <ICodeContextCache, CodeContextCache>() .AddScoped <ICodeContextBuilder, CodeContextBuilder>(); return(builder.BuildServiceProvider()); }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <IDateTimeProvider, DateTimeProvider>(); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder .AddSingleton <IDefinitionsService, DefinitionsService>() .AddSingleton <IHealthChecker, DefinitionsService>(); builder .AddSingleton <IProvidersApiClient, ProvidersApiClient>(); builder.AddSingleton <IProviderSourceDatasetRepository, ProviderSourceDatasetRepository>(ctx => new ProviderSourceDatasetRepository(CreateCosmosDbSettings("providerdatasets"))); builder .AddSingleton <IDatasetService, DatasetService>() .AddSingleton <IHealthChecker, DatasetService>(); builder .AddSingleton <IDatasetDataMergeService, DatasetDataMergeService>(); builder .AddSingleton <IJobManagement, JobManagement>(); builder .AddScoped <IProcessDatasetService, ProcessDatasetService>() .AddScoped <IHealthChecker, ProcessDatasetService>(); builder .AddSingleton <IValidator <CreateNewDatasetModel>, CreateNewDatasetModelValidator>(); builder .AddSingleton <IValidator <DatasetVersionUpdateModel>, DatasetVersionUpdateModelValidator>(); builder .AddSingleton <IValidator <DatasetMetadataModel>, DatasetMetadataModelValidator>(); builder .AddSingleton <IValidator <GetDatasetBlobModel>, GetDatasetBlobModelValidator>(); builder .AddSingleton <IValidator <DatasetDefinition>, DatasetDefinitionValidator>(); builder .AddSingleton <IValidator <CreateDefinitionSpecificationRelationshipModel>, CreateDefinitionSpecificationRelationshipModelValidator>(); builder .AddSingleton <IExcelDatasetWriter, DataDefinitionExcelWriter>(); builder .AddSingleton <IValidator <ExcelPackage>, DatasetWorksheetValidator>(); builder .AddSingleton <IDefinitionChangesDetectionService, DefinitionChangesDetectionService>(); builder .AddSingleton <IDatasetDefinitionNameChangeProcessor, DatasetDefinitionNameChangeProcessor>(); builder .AddSingleton <IValidator <CreateDatasetDefinitionFromTemplateModel>, CreateDatasetDefinitionFromTemplateModelValidator>(); builder .AddSingleton <IPolicyRepository, PolicyRepository>(); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { BlobStorageOptions storageSettings = new BlobStorageOptions(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "datasets"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(storageSettings); return(new BlobClient(blobContainerRepository)); }); builder .AddSingleton <LocalIBlobClient, LocalBlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "datasets"; return(new LocalBlobClient(storageSettings)); }); builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>(ctx => new ProviderSourceDatasetsRepository(CreateCosmosDbSettings("providerdatasets"))); builder.AddSingleton <IDatasetsAggregationsRepository, DatasetsAggregationsRepository>(ctx => new DatasetsAggregationsRepository(CreateCosmosDbSettings("datasetaggregations"))); builder.AddSingleton <IVersionRepository <ProviderSourceDatasetVersion>, VersionRepository <ProviderSourceDatasetVersion> >(ctx => new VersionRepository <ProviderSourceDatasetVersion>(CreateCosmosDbSettings("providerdatasets"), new NewVersionBuilderFactory <ProviderSourceDatasetVersion>())); builder.AddSingleton <IDatasetRepository, DataSetsRepository>(ctx => new DataSetsRepository(CreateCosmosDbSettings("datasets"))); builder .AddSingleton <IDatasetSearchService, DatasetSearchService>() .AddSingleton <IHealthChecker, DatasetSearchService>(); builder.AddSingleton <IDatasetDefinitionSearchService, DatasetDefinitionSearchService>(); builder .AddSingleton <IDefinitionSpecificationRelationshipService, DefinitionSpecificationRelationshipService>() .AddSingleton <IHealthChecker, DefinitionSpecificationRelationshipService>(); builder .AddSingleton <IExcelDatasetReader, ExcelDatasetReader>(); builder .AddSingleton <ICalcsRepository, CalcsRepository>(); builder .AddSingleton <IProviderSourceDatasetVersionKeyProvider, ProviderSourceDatasetVersionKeyProvider>(); builder .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>(); MapperConfiguration dataSetsConfig = new MapperConfiguration(c => { c.AddProfile <DatasetsMappingProfile>(); c.AddProfile <CalculationsMappingProfile>(); c.AddProfile <ProviderMappingProfile>(); }); builder .AddSingleton(dataSetsConfig.CreateMapper()); builder.AddCalculationsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddProvidersInterServiceClient(Configuration); builder.AddPoliciesInterServiceClient(Configuration); builder.AddSearch(Configuration); builder .AddSingleton <ISearchRepository <DatasetIndex>, SearchRepository <DatasetIndex> >(); builder .AddSingleton <ISearchRepository <DatasetDefinitionIndex>, SearchRepository <DatasetDefinitionIndex> >(); builder .AddSingleton <ISearchRepository <DatasetVersionIndex>, SearchRepository <DatasetVersionIndex> >(); builder.AddServiceBus(Configuration); builder.AddCaching(Configuration); builder.AddFeatureToggling(Configuration); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Datasets"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Datasets"); builder.AddLogging("CalculateFunding.Api.Datasets"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration); DatasetsResiliencePolicies resiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <IDatasetsResiliencePolicies>(resiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddTransient <IValidator <DatasetUploadValidationModel>, DatasetUploadValidationModelValidator>(); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddHealthCheckMiddleware(); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Datasets Microservice API"); } builder.AddSingleton <IVersionBulkRepository <ProviderSourceDatasetVersion>, VersionBulkRepository <ProviderSourceDatasetVersion> >((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "providerdatasets"; CosmosRepository cosmos = new CosmosRepository(settings, new CosmosClientOptions { AllowBulkExecution = true }); return(new VersionBulkRepository <ProviderSourceDatasetVersion>(cosmos, new NewVersionBuilderFactory <ProviderSourceDatasetVersion>())); }); builder.AddSingleton <IProviderSourceDatasetBulkRepository, ProviderSourceDatasetBulkRepository>((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "providerdatasets"; CosmosRepository cosmos = new CosmosRepository(settings, new CosmosClientOptions { AllowBulkExecution = true }); return(new ProviderSourceDatasetBulkRepository(cosmos)); }); }
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 <OnScaleUpCosmosDbCollection>(); builder.AddScoped <OnScaleDownCosmosDbCollection>(); builder.AddScoped <OnIncrementalScaleDownCosmosDbCollection>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <ICosmosDbScalingRepositoryProvider, CosmosDbScalingRepositoryProvider>(); builder.AddSingleton <ICosmosDbScalingService, CosmosDbScalingService>(); builder.AddSingleton <ICosmosDbScalingRequestModelBuilder, CosmosDbScalingRequestModelBuilder>(); builder.AddSingleton <ICosmosDbThrottledEventsFilter, CosmosDbThrottledEventsFilter>(); builder.AddSingleton <IValidator <ScalingConfigurationUpdateModel>, ScalingConfigurationUpdateModelValidator>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <CalculationProviderResultsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "calculationresults"; CosmosRepository cosmosRepostory = new CosmosRepository(cosmosDbSettings); return(new CalculationProviderResultsScalingRepository(cosmosRepostory)); }); builder.AddSingleton <ProviderSourceDatasetsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "providerdatasets"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new ProviderSourceDatasetsScalingRepository(cosmosRepository)); }); builder.AddSingleton <PublishedFundingScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "publishedfunding"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new PublishedFundingScalingRepository(cosmosRepository)); }); builder.AddSingleton <CalculationsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "calcs"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new CalculationsScalingRepository(cosmosRepository)); }); builder.AddSingleton <JobsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "jobs"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new JobsScalingRepository(cosmosRepository)); }); builder.AddSingleton <DatasetAggregationsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "datasetaggregations"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new DatasetAggregationsScalingRepository(cosmosRepository)); }); builder.AddSingleton <DatasetsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "datasets"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new DatasetsScalingRepository(cosmosRepository)); }); builder.AddSingleton <ProfilingScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "profiling"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new ProfilingScalingRepository(cosmosRepository)); }); builder.AddSingleton <SpecificationsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "specs"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new SpecificationsScalingRepository(cosmosRepository)); }); builder.AddSingleton <TestResultsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "testresults"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new TestResultsScalingRepository(cosmosRepository)); }); builder.AddSingleton <TestsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "tests"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new TestsScalingRepository(cosmosRepository)); }); builder.AddSingleton <UsersScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "users"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new UsersScalingRepository(cosmosRepository)); }); builder.AddSingleton <ICosmosDbScalingConfigRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "cosmosscalingconfig"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new CosmosDbScalingConfigRepository(cosmosRepository)); }); builder.AddCaching(config); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); builder.AddJobsInterServiceClient(config); builder.AddServiceBus(config, "cosmosdbscaling"); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.CosmosDbScaling"); builder.AddLogging("CalculateFunding.Functions.CosmosDbScaling", config); builder.AddTelemetry(); builder.AddSingleton <ICosmosDbScalingResiliencePolicies>(m => { PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); CosmosDbScalingResiliencePolicies resiliencePolicies = new CosmosDbScalingResiliencePolicies() { ScalingRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ScalingConfigRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); 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 <OnDataDefinitionChanges>(); builder.AddScoped <OnDatasetEvent>(); builder.AddScoped <OnDatasetValidationEvent>(); builder.AddScoped <OnDatasetEventFailure>(); builder.AddScoped <OnDatasetValidationEventFailure>(); builder.AddScoped <OnMapFdzDatasetsEventFired>(); builder.AddScoped <OnMapFdzDatasetsEventFiredFailure>(); builder.AddScoped <OnDeleteDatasets>(); builder.AddScoped <OnDeleteDatasetsFailure>(); } builder.AddSingleton <IDateTimeProvider, DateTimeProvider>(); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IDefinitionsService, DefinitionsService>(); builder .AddSingleton <IProvidersApiClient, ProvidersApiClient>(); builder.AddSingleton <IProviderSourceDatasetRepository, ProviderSourceDatasetRepository>(ctx => new ProviderSourceDatasetRepository(CreateCosmosDbSettings(config, "providerdatasets"))); builder .AddSingleton <IDatasetService, DatasetService>(); builder .AddSingleton <IDatasetDataMergeService, DatasetDataMergeService>(); builder .AddSingleton <IJobManagement, JobManagement>(); builder .AddSingleton <IDeadletterService, DeadletterService>(); builder .AddScoped <IProcessDatasetService, ProcessDatasetService>(); builder .AddSingleton <IValidator <CreateNewDatasetModel>, CreateNewDatasetModelValidator>(); builder .AddSingleton <IValidator <DatasetVersionUpdateModel>, DatasetVersionUpdateModelValidator>(); builder .AddSingleton <IValidator <DatasetMetadataModel>, DatasetMetadataModelValidator>(); builder .AddSingleton <IValidator <GetDatasetBlobModel>, GetDatasetBlobModelValidator>(); builder .AddSingleton <IValidator <CreateDefinitionSpecificationRelationshipModel>, CreateDefinitionSpecificationRelationshipModelValidator>(); builder .AddSingleton <IExcelDatasetWriter, DataDefinitionExcelWriter>(); builder .AddSingleton <IValidator <ExcelPackage>, DatasetWorksheetValidator>(); builder .AddSingleton <IValidator <DatasetDefinition>, DatasetDefinitionValidator>(); builder .AddSingleton <IDefinitionChangesDetectionService, DefinitionChangesDetectionService>(); builder .AddScoped <IDatasetDefinitionNameChangeProcessor, DatasetDefinitionNameChangeProcessor>(); builder .AddSingleton <IValidator <CreateDatasetDefinitionFromTemplateModel>, CreateDatasetDefinitionFromTemplateModelValidator>(); builder .AddSingleton <IPolicyRepository, PolicyRepository>(); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { BlobStorageOptions storageSettings = new BlobStorageOptions(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "datasets"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(storageSettings); return(new BlobClient(blobContainerRepository)); }); builder .AddSingleton <LocalIBlobClient, LocalBlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "datasets"; return(new LocalBlobClient(storageSettings)); }); builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>(ctx => new ProviderSourceDatasetsRepository(CreateCosmosDbSettings(config, "providerdatasets"))); builder.AddSingleton <IDatasetRepository, DataSetsRepository>(ctx => { return(new DataSetsRepository(CreateCosmosDbSettings(config, "datasets"))); }); builder.AddSingleton <IDatasetSearchService, DatasetSearchService>(); builder.AddSingleton <IProviderSourceDatasetVersionKeyProvider, ProviderSourceDatasetVersionKeyProvider>(); builder.AddSingleton <IDatasetDefinitionSearchService, DatasetDefinitionSearchService>(); builder .AddSingleton <IDefinitionSpecificationRelationshipService, DefinitionSpecificationRelationshipService>(); builder .AddSingleton <IExcelDatasetReader, ExcelDatasetReader>(); builder .AddSingleton <ICalcsRepository, CalcsRepository>(); builder.AddTransient <IValidator <DatasetUploadValidationModel>, DatasetUploadValidationModelValidator>(); MapperConfiguration dataSetsConfig = new MapperConfiguration(c => { c.AddProfile <DatasetsMappingProfile>(); c.AddProfile <CalculationsMappingProfile>(); c.AddProfile <ProviderMappingProfile>(); }); builder .AddSingleton(dataSetsConfig.CreateMapper()); builder.AddSingleton <IVersionRepository <ProviderSourceDatasetVersion>, VersionRepository <ProviderSourceDatasetVersion> >(ctx => new VersionRepository <ProviderSourceDatasetVersion>(CreateCosmosDbSettings(config, "providerdatasets"), new NewVersionBuilderFactory <ProviderSourceDatasetVersion>())); builder.AddSingleton <IDatasetsAggregationsRepository, DatasetsAggregationsRepository>(ctx => new DatasetsAggregationsRepository(CreateCosmosDbSettings(config, "datasetaggregations"))); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); 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); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <DatasetIndex>, SearchRepository <DatasetIndex> >(); builder .AddSingleton <ISearchRepository <DatasetDefinitionIndex>, SearchRepository <DatasetDefinitionIndex> >(); builder .AddSingleton <ISearchRepository <DatasetVersionIndex>, SearchRepository <DatasetVersionIndex> >(); builder.AddServiceBus(config, "datasets"); builder.AddCaching(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Datasets"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Datasets"); builder.AddLogging("CalculateFunding.Functions.Datasets"); builder.AddTelemetry(); builder.AddFeatureToggling(config); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); DatasetsResiliencePolicies resiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <IDatasetsResiliencePolicies>(resiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddSingleton <IVersionBulkRepository <ProviderSourceDatasetVersion>, VersionBulkRepository <ProviderSourceDatasetVersion> >((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", settings); settings.ContainerName = "providerdatasets"; CosmosRepository cosmos = new CosmosRepository(settings, new CosmosClientOptions { AllowBulkExecution = true }); return(new VersionBulkRepository <ProviderSourceDatasetVersion>(cosmos, new NewVersionBuilderFactory <ProviderSourceDatasetVersion>())); }); builder.AddSingleton <IProviderSourceDatasetBulkRepository, ProviderSourceDatasetBulkRepository>((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", settings); settings.ContainerName = "providerdatasets"; CosmosRepository cosmos = new CosmosRepository(settings, new CosmosClientOptions { AllowBulkExecution = true }); return(new ProviderSourceDatasetBulkRepository(cosmos)); }); return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <IConfiguration>(config); builder.AddCaching(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 <OnCalcsGenerateAllocationResults>(); builder.AddScoped <OnCalculationGenerateFailure>(); } builder.AddScoped <ICalculationEngineService, CalculationEngineService>(); builder.AddScoped <ICalculationEngine, CalculationEngine>(); builder.AddScoped <IAllocationFactory, AllocationFactory>(); builder.AddScoped <IDeadletterService, DeadletterService>(); builder.AddScoped <IJobManagement, JobManagement>(); builder.AddSingleton <IProviderSourceDatasetVersionKeyProvider, ProviderSourceDatasetVersionKeyProvider>(); builder.AddSingleton <IFileSystemAccess, FileSystemAccess>(); builder.AddSingleton <IAssemblyService, AssemblyService>(); builder.AddSingleton <ICalculationAggregationService, CalculationAggregationService>(); builder.AddScoped <ICalculationEnginePreviewService, CalculationEnginePreviewService>(); builder.AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>(); builder.AddSingleton <IFileSystemCache, FileSystemCache>(); builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>((ctx) => { CosmosDbSettings providerSourceDatasetsCosmosSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", providerSourceDatasetsCosmosSettings); providerSourceDatasetsCosmosSettings.ContainerName = "providerdatasets"; CosmosRepository calcsCosmosRepository = new CosmosRepository(providerSourceDatasetsCosmosSettings, new CosmosClientOptions() { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = 8, MaxTcpConnectionsPerEndpoint = 4, ConsistencyLevel = ConsistencyLevel.Eventual, AllowBulkExecution = true, // MaxRetryAttemptsOnRateLimitedRequests = 1, // MaxRetryWaitTimeOnRateLimitedRequests = new TimeSpan(0, 0, 30), }); ICalculatorResiliencePolicies calculatorResiliencePolicies = ctx.GetService <ICalculatorResiliencePolicies>(); return(new ProviderSourceDatasetsRepository(calcsCosmosRepository, calculatorResiliencePolicies)); }); builder.AddSingleton <IProviderResultCalculationsHashProvider, ProviderResultCalculationsHashProvider>(); builder.AddSingleton <IProviderResultsRepository, ProviderResultsRepository>((ctx) => { CosmosDbSettings calcResultsDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calcResultsDbSettings); calcResultsDbSettings.ContainerName = "calculationresults"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calcResultsDbSettings, new CosmosClientOptions() { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = 8, MaxTcpConnectionsPerEndpoint = 2, // MaxRetryWaitTimeOnRateLimitedRequests = new TimeSpan(0, 0, 30), AllowBulkExecution = true, }); ILogger logger = ctx.GetService <ILogger>(); IProviderResultCalculationsHashProvider calculationsHashProvider = ctx.GetService <IProviderResultCalculationsHashProvider>(); ICalculatorResiliencePolicies calculatorResiliencePolicies = ctx.GetService <ICalculatorResiliencePolicies>(); IResultsApiClient resultsApiClient = ctx.GetService <IResultsApiClient>(); IJobManagement jobManagement = ctx.GetService <IJobManagement>(); return(new ProviderResultsRepository( calcsCosmosRepostory, logger, calculationsHashProvider, calculatorResiliencePolicies, resultsApiClient, jobManagement)); }); builder.AddSingleton <ISourceFileRepository, SourceFileRepository>((ctx) => { BlobStorageOptions blobStorageOptions = new BlobStorageOptions(); config.Bind("AzureStorageSettings", blobStorageOptions); blobStorageOptions.ContainerName = "source"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(blobStorageOptions); return(new SourceFileRepository(blobContainerRepository)); }); builder .AddSingleton <Services.CalcEngine.Interfaces.ICalculationsRepository, Services.CalcEngine.CalculationsRepository>(); builder .AddSingleton <IDatasetAggregationsRepository, DatasetAggregationsRepository>(); builder .AddSingleton <ICancellationTokenProvider, InactiveCancellationTokenProvider>(); builder .AddSingleton <ISourceCodeService, SourceCodeService>(); MapperConfiguration calculationsConfig = new MapperConfiguration(c => { c.AddProfile <CalculationsMappingProfile>(); c.AddProfile <CalcEngineMappingProfile>(); }); builder .AddSingleton(calculationsConfig.CreateMapper()); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddResultsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddDatasetsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddEngineSettings(config); builder.AddServiceBus(config, "calcengine"); builder.AddCaching(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.CalcEngine"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.CalcEngine"); builder.AddLogging("CalculateFunding.Functions.CalcEngine", config); builder.AddTelemetry(); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >(); builder.AddFeatureToggling(config); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); CalculatorResiliencePolicies calcResiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <ICalculatorResiliencePolicies>(calcResiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => new JobManagementResiliencePolicies() { JobsApiClient = calcResiliencePolicies.JobsApiClient }); builder.AddSingleton <IValidator <ICalculatorResiliencePolicies>, CalculatorResiliencePoliciesValidator>(); builder.AddSingleton <ICalculationEngineServiceValidator, CalculationEngineServiceValidator>(); builder.AddSingleton <ISpecificationAssemblyProvider, SpecificationAssemblyProvider>(); builder.AddSingleton <IBlobClient>(ctx => { BlobStorageOptions options = new BlobStorageOptions(); config.Bind("AzureStorageSettings", options); options.ContainerName = "source"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(options); return(new BlobClient(blobContainerRepository)); }); ServicePointManager.DefaultConnectionLimit = 200; return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder.AddFeatureManagement(); // 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 <OnReIndexTemplates>(); } PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); PolicyResiliencePolicies policyResiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { return(new JobManagementResiliencePolicies() { JobsApiClient = policyResiliencePolicies.JobsApiClient }); }); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IFundingStreamService, FundingStreamService>() .AddSingleton <IHealthChecker, FundingStreamService>() .AddSingleton <IValidator <FundingStreamSaveModel>, FundingStreamSaveModelValidator>(); builder .AddSingleton <IFundingPeriodService, FundingPeriodService>() .AddSingleton <IHealthChecker, FundingPeriodService>() .AddSingleton <IFundingPeriodValidator, FundingPeriodValidator>(); builder.AddSingleton <IValidator <FundingPeriodsJsonModel>, FundingPeriodJsonModelValidator>(); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); builder.AddSingleton <ITemplatesReIndexerService, TemplatesReIndexerService>(); builder.AddCaching(config); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <TemplateIndex>, SearchRepository <TemplateIndex> >(); builder.AddSingleton <IPolicyRepository, PolicyRepository>((ctx) => { CosmosDbSettings policyDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", policyDbSettings); policyDbSettings.ContainerName = "policy"; CosmosRepository policyCosmosRepository = new CosmosRepository(policyDbSettings); return(new PolicyRepository(policyCosmosRepository)); }); builder.AddSingleton <ITemplateRepository, TemplateRepository>((ctx) => { CosmosDbSettings policyDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", policyDbSettings); policyDbSettings.ContainerName = "templatebuilder"; CosmosRepository policyCosmosRepository = new CosmosRepository(policyDbSettings); return(new TemplateRepository(policyCosmosRepository)); }); builder.AddServiceBus(config, "policy"); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Policy"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Policy"); builder.AddLogging("CalculateFunding.Functions.Policy", config); builder.AddTelemetry(); builder.AddSingleton <IPolicyResiliencePolicies>(policyResiliencePolicies); builder.AddSingleton <IDeadletterService, DeadletterService>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <ITemplatesReIndexerService, TemplatesReIndexerService>(); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder.AddSingleton <IFundingLineRoundingSettings, FundingLineRoundingSettings>(); builder.AddSingleton <IBatchProfilingOptions, BatchProfilingOptions>(); builder.AddSingleton <IBatchProfilingService, BatchProfilingService>(); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddSingleton <IReProfilingResponseMapper, ReProfilingResponseMapper>(); builder.AddSingleton <IReProfilingRequestBuilder, ReProfilingRequestBuilder>(); builder.AddSingleton <IBatchUploadValidationService, BatchUploadValidationService>(); builder.AddSingleton <IBatchUploadReaderFactory, BatchUploadReaderFactory>(); builder.AddSingleton <IValidator <BatchUploadValidationRequest>, BatchUploadValidationRequestValidation>(); ISqlSettings sqlSettings = new SqlSettings(); config.Bind("saSql", sqlSettings); builder.AddSingleton(sqlSettings); builder.AddSingleton <ISqlPolicyFactory, SqlPolicyFactory>(); builder.AddScoped <ISqlConnectionFactory, SqlConnectionFactory>(); builder.AddScoped <IDataTableImporter, DataTableImporter>(); builder.AddScoped <ISqlImportContextBuilder, SqlImportContextBuilder>(); builder.AddScoped <ISqlImporter, SqlImporter>(); builder.AddScoped <ISqlImportService, SqlImportService>(); builder.AddScoped <ISqlNameGenerator, SqlNameGenerator>(); builder.AddScoped <ISqlSchemaGenerator, SqlSchemaGenerator>(); builder.AddScoped <IQaSchemaService, QaSchemaService>(); builder.AddScoped <IQaRepository, QaRepository>(); builder.AddSingleton <ITemplateMetadataResolver>(ctx => { TemplateMetadataResolver resolver = new TemplateMetadataResolver(); ILogger logger = ctx.GetService <ILogger>(); TemplateMetadataSchema10.TemplateMetadataGenerator schema10Generator = new TemplateMetadataSchema10.TemplateMetadataGenerator(logger); resolver.Register("1.0", schema10Generator); TemplateMetadataSchema11.TemplateMetadataGenerator schema11Generator = new TemplateMetadataSchema11.TemplateMetadataGenerator(logger); resolver.Register("1.1", schema11Generator); return(resolver); }); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); CosmosDbSettings settings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; builder.AddSingleton(settings); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddFeatureManagement(); builder.AddSingleton <IConfiguration>(ctx => config); builder .AddScoped <IPublishedFundingQueryBuilder, PublishedFundingQueryBuilder>(); builder .AddSingleton <IPublishingEngineOptions>(_ => new PublishingEngineOptions(config)); builder.AddSingleton <IPublishedFundingRepository, PublishedFundingRepository>((ctx) => { CosmosDbSettings calssDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calssDbSettings); calssDbSettings.ContainerName = "publishedfunding"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calssDbSettings); IPublishedFundingQueryBuilder publishedFundingQueryBuilder = ctx.GetService <IPublishedFundingQueryBuilder>(); return(new PublishedFundingRepository(calcsCosmosRepostory, publishedFundingQueryBuilder)); }); builder.AddSingleton <IPublishedFundingBulkRepository, PublishedFundingBulkRepository>((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; IPublishingEngineOptions publishingEngineOptions = ctx.GetService <IPublishingEngineOptions>(); CosmosRepository calcsCosmosRepository = new CosmosRepository(settings, publishingEngineOptions.AllowBatching ? new CosmosClientOptions { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = publishingEngineOptions.MaxRequestsPerTcpConnectionPublishedFundingCosmosBulkOptions, MaxTcpConnectionsPerEndpoint = publishingEngineOptions.MaxTcpConnectionsPerEndpointPublishedFundingCosmosBulkOptions, ConsistencyLevel = ConsistencyLevel.Eventual, AllowBulkExecution = true } : null); IPublishingResiliencePolicies publishingResiliencePolicies = ctx.GetService <IPublishingResiliencePolicies>(); return(new PublishedFundingBulkRepository(publishingResiliencePolicies, publishingEngineOptions, calcsCosmosRepository)); }); CosmosDbSettings publishedfundingCosmosSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", publishedfundingCosmosSettings); publishedfundingCosmosSettings.ContainerName = "publishedfunding"; builder.AddSingleton(publishedfundingCosmosSettings); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); builder.AddCaching(config); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <PublishedProviderIndex>, SearchRepository <PublishedProviderIndex> >(); builder .AddSingleton <ISearchRepository <PublishedFundingIndex>, SearchRepository <PublishedFundingIndex> >(); // 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(_ => new OnRefreshFunding(_.GetService <ILogger>(), _.GetService <IRefreshService>(), _.GetService <IMessengerService>(), _.GetService <IUserProfileProvider>(), true)); builder.AddScoped(_ => new OnApproveAllProviderFunding(_.GetService <ILogger>(), _.GetService <IApproveService>(), _.GetService <IMessengerService>(), _.GetService <IUserProfileProvider>(), true)); builder.AddScoped(_ => new OnPublishAllProviderFunding(_.GetService <ILogger>(), _.GetService <IPublishService>(), _.GetService <IMessengerService>(), _.GetService <IUserProfileProvider>(), true)); builder.AddScoped <OnRunSqlImport>(); builder.AddScoped <OnRefreshFundingFailure>(); builder.AddScoped <OnApproveAllProviderFundingFailure>(); builder.AddScoped <OnPublishAllProviderFundingFailure>(); builder.AddScoped <OnPublishIntegrityCheck>(); builder.AddScoped <OnPublishIntegrityCheckFailure>(); builder.AddScoped <OnDeletePublishedProviders>(); builder.AddScoped <OnDeletePublishedProvidersFailure>(); builder.AddScoped <OnReIndexPublishedProviders>(); builder.AddScoped <OnGeneratePublishedFundingCsv>(); builder.AddScoped <OnGeneratePublishedFundingCsvFailure>(); builder.AddScoped <OnGeneratePublishedProviderEstateCsv>(); builder.AddScoped <OnGeneratePublishedProviderEstateCsvFailure>(); builder.AddScoped(_ => new OnApproveBatchProviderFunding(_.GetService <ILogger>(), _.GetService <IApproveService>(), _.GetService <IMessengerService>(), _.GetService <IUserProfileProvider>(), true)); builder.AddScoped <OnApproveBatchProviderFundingFailure>(); builder.AddScoped(_ => new OnPublishBatchProviderFunding(_.GetService <ILogger>(), _.GetService <IPublishService>(), _.GetService <IMessengerService>(), _.GetService <IUserProfileProvider>(), true)); builder.AddScoped <OnPublishBatchProviderFundingFailure>(); builder.AddScoped <OnPublishedFundingUndo>(); builder.AddScoped <OnBatchPublishedProviderValidation>(); builder.AddScoped <OnBatchPublishedProviderValidationFailure>(); } builder.AddSingleton <ISpecificationService, SpecificationService>(); builder.AddSingleton <IProviderService, ProviderService>(); builder.AddSingleton <IPublishedFundingService, PublishedFundingService>(); builder.AddSingleton <IPoliciesService, PoliciesService>(); builder.AddSingleton <IPublishedFundingVersionDataService, PublishedFundingVersionDataService>(); builder.AddScoped <IRefreshService, RefreshService>(); builder.AddScoped <IVariationService, VariationService>(); builder.AddTransient <IRecordVariationErrors, VariationErrorRecorder>(); builder.AddTransient <IApplyProviderVariations, ProviderVariationsApplication>(); builder.AddTransient <IDetectProviderVariations, ProviderVariationsDetection>(); builder.AddTransient <IVariationStrategyServiceLocator, VariationStrategyServiceLocator>(); builder.AddTransient <IVariationStrategy, ClosureVariationStrategy>(); builder.AddTransient <IVariationStrategy, ClosureWithSuccessorVariationStrategy>(); builder.AddTransient <IVariationStrategy, ProviderMetadataVariationStrategy>(); builder.AddTransient <IVariationStrategy, PupilNumberSuccessorVariationStrategy>(); builder.AddTransient <IVariationStrategy, FundingUpdatedVariationStrategy>(); builder.AddTransient <IVariationStrategy, ProfilingUpdatedVariationStrategy>(); builder.AddTransient <IVariationStrategy, DsgTotalAllocationChangeVariationStrategy>(); builder.AddTransient <IVariationStrategy, ReProfilingVariationStrategy>(); builder.AddSingleton <IReProfilingResponseMapper, ReProfilingResponseMapper>(); builder.AddScoped <IApproveService, ApproveService>(); builder.AddSingleton <IJobTracker, JobTracker>(); builder.AddScoped <IPublishService, PublishService>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <ISpecificationFundingStatusService, SpecificationFundingStatusService>(); builder.AddScoped <ICsvUtils, CsvUtils>(); builder.AddSingleton <IFileSystemAccess, FileSystemAccess>(); builder.AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>(); builder.AddScoped <IReApplyCustomProfiles, ReApplyCustomProfiles>(); builder.AddScoped <IPublishedProviderErrorDetection, PublishedProviderErrorDetection>(); builder.AddTransient <IErrorDetectionStrategyLocator, ErrorDetectionStrategyLocator>(); builder.AddTransient <IDetectPublishedProviderErrors, FundingLineValueProfileMismatchErrorDetector>(); builder.AddTransient <IDetectPublishedProviderErrors, TrustIdMismatchErrorDetector>(); builder.AddScoped <IGeneratePublishedFundingCsvJobsCreationLocator, GeneratePublishedFundingCsvJobsCreationLocator>(); builder.AddScoped <IGeneratePublishedFundingCsvJobsCreation, GenerateRefreshPublishedFundingCsvJobsCreation>(); builder.AddScoped <IGeneratePublishedFundingCsvJobsCreation, GenerateApprovePublishedFundingCsvJobsCreation>(); builder.AddScoped <IGeneratePublishedFundingCsvJobsCreation, GenerateReleasePublishedFundingCsvJobsCreation>(); builder.AddScoped <IFundingLineCsvGenerator, FundingLineCsvGenerator>(); builder.AddScoped <IFundingLineCsvTransform, PublishedProviderFundingLineCsvTransform>(); builder.AddScoped <IFundingLineCsvTransform, PublishedProviderVersionFundingLineCsvTransform>(); builder.AddScoped <IFundingLineCsvTransform, PublishedProviderDeliveryProfileFundingLineCsvTransform>(); builder.AddScoped <IFundingLineCsvTransform, PublishedProviderVersionFundingLineProfileValuesCsvTransform>(); builder.AddScoped <IFundingLineCsvTransform, PublishedFundingFundingLineGroupingCsvTransform>(); builder.AddScoped <IFundingLineCsvTransform, PublishedFundingVersionFundingLineGroupingCsvTransform>(); builder.AddScoped <IFundingLineCsvTransform, PublishedGroupsFundingLineCsvTransform>(); builder.AddScoped <IFundingLineCsvTransformServiceLocator, FundingLineCsvTransformServiceLocator>(); builder.AddScoped <IPublishedFundingPredicateBuilder, PublishedFundingPredicateBuilder>(); builder.AddScoped <IFundingLineCsvBatchProcessorServiceLocator, FundingLineCsvBatchProcessorServiceLocator>(); builder.AddScoped <IFundingLineCsvBatchProcessor, PublishedProviderCsvBatchProcessor>(); builder.AddScoped <IFundingLineCsvBatchProcessor, PublishedProviderVersionCsvBatchProcessor>(); builder.AddScoped <IFundingLineCsvBatchProcessor, PublishedFundingOrganisationGroupCsvBatchProcessor>(); builder.AddScoped <IFundingLineCsvBatchProcessor, PublishedFundingVersionOrganisationGroupCsvBatchProcessor>(); builder.AddScoped <IFundingLineCsvBatchProcessor, PublishedGroupsCsvBatchProcessor>(); builder.AddTransient <ICreateGeneratePublishedFundingCsvJobs, GeneratePublishedFundingCsvJobCreation>(); builder.AddScoped <IPublishedProviderEstateCsvGenerator, PublishedProviderEstateCsvGenerator>() .AddSingleton <IHealthChecker, PublishedProviderEstateCsvGenerator>(); builder.AddScoped <IPublishedProviderCsvTransformServiceLocator, PublishedProviderCsvTransformServiceLocator>(); builder.AddScoped <IPublishedProviderCsvTransform, PublishedProviderEstateCsvTransform>(); builder.AddScoped <ICreateGeneratePublishedProviderEstateCsvJobs, CreateGeneratePublishedProviderEstateCsvJobs>(); builder .AddSingleton <IPublishedProviderVersioningService, PublishedProviderVersioningService>() .AddSingleton <IHealthChecker, PublishedProviderVersioningService>(); builder .AddSingleton <IPublishedProviderStatusUpdateService, PublishedProviderStatusUpdateService>() .AddSingleton <IHealthChecker, PublishedProviderStatusUpdateService>(); builder .AddSingleton <IPublishedProviderVersionService, PublishedProviderVersionService>() .AddSingleton <IHealthChecker, PublishedProviderVersionService>(); builder .AddSingleton <IPublishedSearchService, PublishedSearchService>() .AddSingleton <IHealthChecker, PublishedSearchService>(); builder .AddSingleton <IPublishedProviderStatusUpdateSettings>(_ => { PublishedProviderStatusUpdateSettings settings = new PublishedProviderStatusUpdateSettings(); config.Bind("PublishedProviderStatusUpdateSettings", settings); return(settings); } ); builder .AddSingleton <Common.Storage.IBlobClient, CommonBlobClient>((ctx) => { BlobStorageOptions storageSettings = new BlobStorageOptions(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "publishedproviderversions"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(storageSettings); return(new CommonBlobClient(blobContainerRepository)); }); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "publishedproviderversions"; return(new BlobClient(storageSettings)); }); builder.AddSingleton <IVersionRepository <PublishedProviderVersion>, VersionRepository <PublishedProviderVersion> >((ctx) => { CosmosDbSettings publishedProviderVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", publishedProviderVersioningDbSettings); publishedProviderVersioningDbSettings.ContainerName = "publishedfunding"; CosmosRepository resultsRepostory = new CosmosRepository(publishedProviderVersioningDbSettings); return(new VersionRepository <PublishedProviderVersion>(resultsRepostory, new NewVersionBuilderFactory <PublishedProviderVersion>())); }); builder.AddSingleton <IVersionBulkRepository <PublishedProviderVersion>, VersionBulkRepository <PublishedProviderVersion> >((ctx) => { CosmosDbSettings PublishedProviderVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", PublishedProviderVersioningDbSettings); PublishedProviderVersioningDbSettings.ContainerName = "publishedfunding"; IPublishingEngineOptions publishingEngineOptions = ctx.GetService <IPublishingEngineOptions>(); CosmosRepository cosmosRepository = new CosmosRepository(PublishedProviderVersioningDbSettings, publishingEngineOptions.AllowBatching ? new CosmosClientOptions { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = publishingEngineOptions.MaxRequestsPerTcpConnectionPublishedFundingCosmosBulkOptions, MaxTcpConnectionsPerEndpoint = publishingEngineOptions.MaxTcpConnectionsPerEndpointPublishedFundingCosmosBulkOptions, ConsistencyLevel = ConsistencyLevel.Eventual, AllowBulkExecution = true } : null); return(new VersionBulkRepository <PublishedProviderVersion>(cosmosRepository, new NewVersionBuilderFactory <PublishedProviderVersion>())); }); builder.AddSingleton <IVersionRepository <PublishedFundingVersion>, VersionRepository <PublishedFundingVersion> >((ctx) => { CosmosDbSettings ProviderSourceDatasetVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", ProviderSourceDatasetVersioningDbSettings); ProviderSourceDatasetVersioningDbSettings.ContainerName = "publishedfunding"; CosmosRepository cosmosRepository = new CosmosRepository(ProviderSourceDatasetVersioningDbSettings); return(new VersionRepository <PublishedFundingVersion>(cosmosRepository, new NewVersionBuilderFactory <PublishedFundingVersion>())); }); builder.AddSingleton <IVersionBulkRepository <PublishedFundingVersion>, VersionBulkRepository <PublishedFundingVersion> >((ctx) => { CosmosDbSettings PublishedFundingVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", PublishedFundingVersioningDbSettings); PublishedFundingVersioningDbSettings.ContainerName = "publishedfunding"; IPublishingEngineOptions publishingEngineOptions = ctx.GetService <IPublishingEngineOptions>(); CosmosRepository cosmosRepository = new CosmosRepository(PublishedFundingVersioningDbSettings, publishingEngineOptions.AllowBatching ? new CosmosClientOptions { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = publishingEngineOptions.MaxRequestsPerTcpConnectionPublishedFundingCosmosBulkOptions, MaxTcpConnectionsPerEndpoint = publishingEngineOptions.MaxTcpConnectionsPerEndpointPublishedFundingCosmosBulkOptions, ConsistencyLevel = ConsistencyLevel.Eventual, AllowBulkExecution = true } : null); return(new VersionBulkRepository <PublishedFundingVersion>(cosmosRepository, new NewVersionBuilderFactory <PublishedFundingVersion>())); }); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>((ctx) => { CosmosDbSettings calssDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calssDbSettings); calssDbSettings.ContainerName = "calculationresults"; IPublishingEngineOptions publishingEngineOptions = ctx.GetService <IPublishingEngineOptions>(); CosmosRepository calcsCosmosRepository = new CosmosRepository(calssDbSettings, new CosmosClientOptions { ConnectionMode = ConnectionMode.Direct, RequestTimeout = new TimeSpan(0, 0, 15), MaxRequestsPerTcpConnection = publishingEngineOptions.MaxRequestsPerTcpConnectionCalculationsCosmosBulkOptions, MaxTcpConnectionsPerEndpoint = publishingEngineOptions.MaxTcpConnectionsPerEndpointCalculationsCosmosBulkOptions, ConsistencyLevel = ConsistencyLevel.Eventual, AllowBulkExecution = true }); return(new CalculationResultsRepository(calcsCosmosRepository)); }); builder.AddSingleton <ICalculationResultsService, CalculationResultsService>(); builder.AddSingleton <IPublishedProviderDataGenerator, PublishedProviderDataGenerator>(); builder.AddSingleton <IFundingLineTotalAggregator, FundingLineTotalAggregator>(); builder .AddSingleton <IProfilingService, ProfilingService>() .AddSingleton <IHealthChecker, ProfilingService>(); builder.AddSingleton(new MapperConfiguration(_ => { _.AddProfile <PublishingServiceMappingProfile>(); }).CreateMapper()); builder.AddSingleton <IPublishedProviderDataPopulator, PublishedProviderDataPopulator>(); builder.AddSingleton <IPublishIntegrityCheckService, PublishIntegrityCheckService>(); builder.AddSingleton <IPublishedProviderContentsGeneratorResolver>(ctx => { PublishedProviderContentsGeneratorResolver resolver = new PublishedProviderContentsGeneratorResolver(); resolver.Register("1.0", new Generators.Schema10.PublishedProviderContentsGenerator()); resolver.Register("1.1", new Generators.Schema11.PublishedProviderContentsGenerator()); return(resolver); }); builder.AddSingleton <IPublishedFundingContentsGeneratorResolver>(ctx => { PublishedFundingContentsGeneratorResolver resolver = new PublishedFundingContentsGeneratorResolver(); resolver.Register("1.0", new Generators.Schema10.PublishedFundingContentsGenerator()); resolver.Register("1.1", new Generators.Schema11.PublishedFundingContentsGenerator()); return(resolver); }); builder.AddSingleton <IPublishedFundingIdGeneratorResolver>(ctx => { PublishedFundingIdGeneratorResolver resolver = new PublishedFundingIdGeneratorResolver(); IPublishedFundingIdGenerator v10Generator = new Generators.Schema10.PublishedFundingIdGenerator(); resolver.Register("1.0", v10Generator); resolver.Register("1.1", v10Generator); return(resolver); }); builder.AddSingleton <IDeadletterService, DeadletterService>(); builder.AddSingleton <IPublishedProviderReIndexerService, PublishedProviderReIndexerService>(); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Publishing"); builder.AddLogging("CalculateFunding.Functions.Publishing", config); builder.AddTelemetry(); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); ResiliencePolicies publishingResiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddServiceBus(config, "publishing"); builder.AddPublishingServices(config); builder.AddSingleton <IPublishingResiliencePolicies>(publishingResiliencePolicies); builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddProvidersInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddFundingDataServiceInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSingleton <ITransactionResiliencePolicies>((ctx) => new TransactionResiliencePolicies() { TransactionPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings) }); builder.AddSingleton <ITransactionFactory, TransactionFactory>(); builder .AddProfilingInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddScoped <IPublishedFundingUndoJobService, PublishedFundingUndoJobService>(); builder.AddScoped <IPublishedFundingUndoJobCreation, PublishedFundingUndoJobCreation>(); builder.AddScoped <IPublishedFundingUndoTaskFactoryLocator, PublishedFundingUndoTaskFactoryLocator>(); builder.AddSingleton <IPublishedFundingUndoTaskFactory, SoftDeletePublishedFundingUndoTaskFactory>(); builder.AddSingleton <IPublishedFundingUndoTaskFactory, HardDeletePublishedFundingUndoTaskFactory>(); builder.AddSingleton <IPublishedFundingUndoCosmosRepository>(ctx => { CosmosDbSettings settings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; return(new PublishedFundingUndoCosmosRepository(ctx.GetService <IPublishingResiliencePolicies>(), new CosmosRepository(settings))); }); builder.AddSingleton <IPublishedFundingUndoBlobStoreRepository>(ctx => { BlobStorageOptions settings = new BlobStorageOptions(); config.Bind("AzureStorageSettings", settings); settings.ContainerName = "publishedproviderversions"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(settings); return(new PublishedFundingUndoBlobStoreRepository(new CommonBlobClient(blobContainerRepository), ctx.GetService <IPublishingResiliencePolicies>(), ctx.GetService <ILogger>())); }); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <IFundingLineRoundingSettings, FundingLineRoundingSettings>(); builder.AddScoped <ICodeContextCache, CodeContextCache>() .AddScoped <ICodeContextBuilder, CodeContextBuilder>(); builder.AddSingleton <ICalculationFundingLineQueryService, CalculationFundingLineQueryService>(); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton(Configuration); builder .AddScoped <IHealthChecker, ControllerResolverHealthCheck>(); builder .AddSingleton <ICalculationsRepository, CalculationsRepository>((ctx) => { CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calcsVersioningDbSettings); calcsVersioningDbSettings.ContainerName = "calcs"; CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings); return(new CalculationsRepository(resultsRepostory)); }); builder .AddScoped <ICalculationService, CalculationService>() .AddSingleton <ICalculationNameInUseCheck, CalculationNameInUseCheck>() .AddScoped <IInstructionAllocationJobCreation, InstructionAllocationJobCreation>() .AddScoped <IHealthChecker, CalculationService>() .AddScoped <ICreateCalculationService, CreateCalculationService>(); builder .AddScoped <IQueueReIndexSpecificationCalculationRelationships, QueueReIndexSpecificationCalculationRelationships>(); builder .AddSingleton <ICalculationCodeReferenceUpdate, CalculationCodeReferenceUpdate>(); builder .AddSingleton <ICalculationsSearchService, CalculationSearchService>() .AddSingleton <IHealthChecker, CalculationSearchService>(); builder .AddSingleton <IValidator <Calculation>, CalculationModelValidator>(); builder .AddScoped <IValidator <CalculationCreateModel>, CalculationCreateModelValidator>(); builder .AddScoped <IValidator <CalculationEditModel>, CalculationEditModelValidator>(); builder .AddScoped <IPreviewService, PreviewService>() .AddScoped <IHealthChecker, PreviewService>(); builder .AddSingleton <ICompilerFactory, CompilerFactory>(); builder .AddSingleton <CSharpCompiler>() .AddSingleton <VisualBasicCompiler>() .AddSingleton <VisualBasicSourceFileGenerator>(); builder .AddSingleton <ISourceFileGeneratorProvider, SourceFileGeneratorProvider>(); builder .AddSingleton <IValidator <PreviewRequest>, PreviewRequestModelValidator>(); builder .AddScoped <IBuildProjectsService, BuildProjectsService>() .AddScoped <IHealthChecker, BuildProjectsService>(); builder .AddScoped <IDatasetReferenceService, DatasetReferenceService>(); builder .AddSingleton <IBuildProjectsRepository, BuildProjectsRepository>((ctx) => { CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calcsVersioningDbSettings); calcsVersioningDbSettings.ContainerName = "calcs"; CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings); return(new BuildProjectsRepository(resultsRepostory)); }); builder .AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>(); builder.AddSingleton <ISourceCodeService, SourceCodeService>(); builder .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); builder.AddScoped <ICalculationEngineRunningChecker, CalculationEngineRunningChecker>(); builder .AddScoped <IApproveAllCalculationsJobAction, ApproveAllCalculationsJobAction>(); builder.AddSingleton <ISourceFileRepository, SourceFileRepository>((ctx) => { BlobStorageOptions blobStorageOptions = new BlobStorageOptions(); Configuration.Bind("AzureStorageSettings", blobStorageOptions); blobStorageOptions.ContainerName = "source"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(blobStorageOptions); return(new SourceFileRepository(blobContainerRepository)); }); builder .AddSingleton <IVersionRepository <CalculationVersion>, VersionRepository <CalculationVersion> >((ctx) => { CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calcsVersioningDbSettings); calcsVersioningDbSettings.ContainerName = "calcs"; CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings); return(new VersionRepository <CalculationVersion>(resultsRepostory, new NewVersionBuilderFactory <CalculationVersion>())); }); builder .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>(); MapperConfiguration calcConfig = new MapperConfiguration(c => { c.AddProfile <CalculationsMappingProfile>(); }); builder .AddSingleton(calcConfig.CreateMapper()); builder.AddSearch(Configuration); builder .AddSingleton <ISearchRepository <CalculationIndex>, SearchRepository <CalculationIndex> >(); builder .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >(); builder.AddServiceBus(Configuration); builder.AddScoped <IJobManagement, JobManagement>(); builder.AddScoped <ICalculationsFeatureFlag, CalculationsFeatureFlag>(); builder.AddScoped <IGraphRepository, GraphRepository>(); builder.AddProvidersInterServiceClient(Configuration); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddDatasetsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddGraphInterServiceClient(Configuration); builder.AddPoliciesInterServiceClient(Configuration); builder.AddResultsInterServiceClient(Configuration); builder.AddCalcEngineInterServiceClient(Configuration); builder.AddCaching(Configuration); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Calcs"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Calcs"); builder.AddLogging("CalculateFunding.Api.Calcs"); builder.AddTelemetry(); builder.AddEngineSettings(Configuration); builder.AddFeatureToggling(Configuration); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ResiliencePolicies resiliencePolicies = CreateResiliencePolicies(totalNetworkRequestsPolicy); builder.AddSingleton <ICalcsResiliencePolicies>(resiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { return(new JobManagementResiliencePolicies() { JobsApiClient = resiliencePolicies.JobsApiClient, }); }); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Calcs Microservice API", version: "v1"); } }