public void TemplateMetadataResolver_GivenGeneratorRegisteredInCorrectly_NoGeneratorReturned() { //Arrange Exception exception = null; TemplateMetadataResolver templateMetadataResolver = CreateTemplateResolver(); //Act templateMetadataResolver.Register("2.0", CreateTemplateGenerator(_schemaVersion)); bool contains = templateMetadataResolver.Contains(_schemaVersion); try { ITemplateMetadataGenerator generator = templateMetadataResolver.GetService(_schemaVersion); } catch (Exception ex) { exception = ex; } //Assert contains .Should() .Be(false); exception.Message .Should() .Be($"Unable to find a registered resolver for schema version : {_schemaVersion}"); }
public void RegisterTemplateBuilderComponents(IServiceCollection builder) { CosmosDbSettings settings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "templatebuilder"; CosmosRepository cosmos = new CosmosRepository(settings); builder .AddSingleton <ITemplateBuilderService, TemplateBuilderService>() .AddSingleton <ITemplateBlobService, TemplateBlobService>() .AddSingleton <IHealthChecker, TemplateBuilderService>() .AddSingleton <AbstractValidator <TemplateCreateCommand>, TemplateCreateCommandValidator>() .AddSingleton <AbstractValidator <TemplateCreateAsCloneCommand>, TemplateCreateAsCloneCommandValidator>() .AddSingleton <AbstractValidator <TemplateFundingLinesUpdateCommand>, TemplateContentUpdateCommandValidator>() .AddSingleton <AbstractValidator <TemplateDescriptionUpdateCommand>, TemplateDescriptionUpdateCommandValidator>() .AddSingleton <AbstractValidator <TemplatePublishCommand>, TemplatePublishCommandValidator>() .AddSingleton <AbstractValidator <Reference>, AuthorValidator>() .AddSingleton <AbstractValidator <FindTemplateVersionQuery>, FindTemplateVersionQueryValidator>() .AddSingleton <ITemplateRepository, TemplateRepository>(ctx => new TemplateRepository(cosmos)) .AddSingleton <ITemplateVersionRepository, TemplateVersionRepository>(ctx => new TemplateVersionRepository(cosmos, new NewVersionBuilderFactory <TemplateVersion>())) .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); }); }
private DTO.Template ResolveTemplateMetadata(Template template) { if (template == null) { return(null); } var resolver = new TemplateMetadataResolver(_metadataUnitOfWork); return(resolver.Resolve(template)); }
private static ITemplateMetadataResolver CreateMetadataResolver(string schemaVersion = "1.0", ITemplateMetadataGenerator tempateMetadataGenerator = null) { TemplateMetadataResolver resolver = new TemplateMetadataResolver(); switch (schemaVersion) { case "1.0": { resolver.Register(schemaVersion, tempateMetadataGenerator ?? new TemplateMetadataSchema10.TemplateMetadataGenerator(CreateLogger())); break; } } return(resolver); }
public void TemplateMetadataResolver_GivenGeneratorRegisteredInCorrectly_TryGetReturnsFalse() { //Arrange TemplateMetadataResolver templateMetadataResolver = CreateTemplateResolver(); //Act templateMetadataResolver.Register("2.0", CreateTemplateGenerator(_schemaVersion)); bool contains = templateMetadataResolver.TryGetService(_schemaVersion, out ITemplateMetadataGenerator generator); //Assert contains .Should() .Be(false); AssertionExtensions.Should((object)generator) .BeNull(); }
public void TemplateMetadataResolver_GivenGeneratorRegisteredCorrectly_ReturnsCorrectGenerator() { //Arrange TemplateMetadataResolver templateMetadataResolver = CreateTemplateResolver(); //Act templateMetadataResolver.Register(_schemaVersion, CreateTemplateGenerator(_schemaVersion)); bool contains = templateMetadataResolver.Contains(_schemaVersion); ITemplateMetadataGenerator generator = templateMetadataResolver.GetService(_schemaVersion); //Assert contains .Should() .Be(true); AssertionExtensions.Should((object)generator) .BeOfType <TemplateMetadataGenerator>(); }
public void TemplateMetadataResolver_GivenGeneratorRegisteredInCorrectly_TryGetReturnsTrue() { //Arrange TemplateMetadataResolver templateMetadataResolver = CreateTemplateResolver(); ITemplateMetadataGenerator registeredGenerator = CreateTemplateGenerator(_schemaVersion); //Act templateMetadataResolver.Register(_schemaVersion, registeredGenerator); bool contains = templateMetadataResolver.TryGetService(_schemaVersion, out ITemplateMetadataGenerator generator); //Assert contains .Should() .Be(true); generator .Should() .Be(generator); }
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"); } }
private void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <IBatchProfilingOptions, BatchProfilingOptions>(); builder.AddSingleton <IBatchProfilingService, BatchProfilingService>(); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddSingleton <IReProfilingResponseMapper, ReProfilingResponseMapper>(); builder.AddSingleton <IBatchUploadQueryService, BatchUploadQueryService>(); builder.AddSingleton <IUniqueIdentifierProvider, UniqueIdentifierProvider>(); builder.AddSingleton <IBatchUploadValidationService, BatchUploadValidationService>(); builder.AddSingleton <IBatchUploadReaderFactory, BatchUploadReaderFactory>(); builder.AddSingleton <IValidator <BatchUploadValidationRequest>, BatchUploadValidationRequestValidation>(); builder.AddSingleton <IPublishedProviderUpdateDateService, PublishedProviderUpdateDateService>(); ISqlSettings sqlSettings = new SqlSettings(); Configuration.Bind("saSql", sqlSettings); builder.AddSingleton(sqlSettings); builder.AddSingleton <IBatchUploadService, BatchUploadService>(); builder.AddScoped <IDataTableImporter, DataTableImporter>(); builder.AddScoped <ISqlImportContextBuilder, SqlImportContextBuilder>(); builder.AddSingleton <ISqlPolicyFactory, SqlPolicyFactory>(); builder.AddScoped <ISqlConnectionFactory, SqlConnectionFactory>(); 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(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; builder.AddSingleton(settings); 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 <IProfilePatternPreview, ProfilePatternPreview>(); builder.AddSingleton <IReProfilingRequestBuilder, ReProfilingRequestBuilder>(); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder.AddSingleton <IProfileHistoryService, ProfileHistoryService>(); builder.AddSingleton <IDateTimeProvider, DateTimeProvider>(); builder .AddSingleton <IPublishedProviderVersionService, PublishedProviderVersionService>() .AddSingleton <IHealthChecker, PublishedProviderVersionService>(); builder.AddSingleton <ISpecificationFundingStatusService, SpecificationFundingStatusService>(); builder .AddSingleton <IPublishedSearchService, PublishedSearchService>() .AddSingleton <IHealthChecker, PublishedSearchService>(); builder.AddSingleton <IPoliciesService, PoliciesService>(); builder.AddSingleton <IPublishedProviderStatusService, PublishedProviderStatusService>(); builder.AddScoped <IProfileTotalsService, ProfileTotalsService>(); builder.AddSingleton <IFundingConfigurationService, FundingConfigurationService>(); builder.AddScoped <IFundingStreamPaymentDatesQuery, FundingStreamPaymentDatesQuery>(); builder.AddScoped <IFundingStreamPaymentDatesIngestion, FundingStreamPaymentDatesIngestion>(); builder.AddSingleton <ICsvUtils, CsvUtils>(); builder.AddScoped <ICustomProfileService, CustomProfilingService>(); builder.AddScoped <IValidator <ApplyCustomProfileRequest>, ApplyCustomProfileRequestValidator>(); builder.AddSingleton <IPublishedProviderStatusUpdateService, PublishedProviderStatusUpdateService>(); builder.AddSingleton <IPublishedProviderVersioningService, PublishedProviderVersioningService>(); builder.AddSingleton <IJobTracker, JobTracker>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <IVersionRepository <PublishedProviderVersion>, VersionRepository <PublishedProviderVersion> >((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; CosmosRepository cosmos = new CosmosRepository(settings); return(new VersionRepository <PublishedProviderVersion>(cosmos, new NewVersionBuilderFactory <PublishedProviderVersion>())); }); builder.AddSingleton <IVersionBulkRepository <PublishedProviderVersion>, VersionBulkRepository <PublishedProviderVersion> >((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; CosmosRepository cosmos = new CosmosRepository(settings); return(new VersionBulkRepository <PublishedProviderVersion>(cosmos, new NewVersionBuilderFactory <PublishedProviderVersion>())); }); builder .AddSingleton <IPublishedProviderStatusUpdateSettings>(_ => { PublishedProviderStatusUpdateSettings settings = new PublishedProviderStatusUpdateSettings(); Configuration.Bind("PublishedProviderStatusUpdateSettings", settings); return(settings); } ); builder.AddHttpClient(HttpClientKeys.Profiling, c => { ApiOptions apiOptions = new ApiOptions(); Configuration.Bind("providerProfilingClient", apiOptions); Services.Core.Extensions.ServiceCollectionExtensions.SetDefaultApiClientConfigurationOptions(c, apiOptions, builder); }) .ConfigurePrimaryHttpMessageHandler(() => new ApiClientHandler()) .AddTransientHttpErrorPolicy(c => c.WaitAndRetryAsync(new[] { TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5) })) .AddTransientHttpErrorPolicy(c => c.CircuitBreakerAsync(100, TimeSpan.FromSeconds(30))); builder.AddSingleton <IFundingStreamPaymentDatesRepository>((ctx) => { CosmosDbSettings cosmosSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", cosmosSettings); cosmosSettings.ContainerName = "profiling"; return(new FundingStreamPaymentDatesRepository(new CosmosRepository(cosmosSettings))); }); builder .AddSingleton <IPublishedFundingQueryBuilder, PublishedFundingQueryBuilder>(); builder.AddSingleton <IPublishedFundingRepository, PublishedFundingRepository>((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; CosmosRepository calcsCosmosRepository = new CosmosRepository(settings); IPublishedFundingQueryBuilder publishedFundingQueryBuilder = ctx.GetService <IPublishedFundingQueryBuilder>(); return(new PublishedFundingRepository(calcsCosmosRepository, publishedFundingQueryBuilder)); }); builder .AddSingleton <IPublishingEngineOptions>(_ => new PublishingEngineOptions(Configuration)); builder.AddSingleton <IPublishedFundingBulkRepository, PublishedFundingBulkRepository>((ctx) => { CosmosDbSettings settings = new CosmosDbSettings(); Configuration.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 = 4, ConsistencyLevel = ConsistencyLevel.Eventual, AllowBulkExecution = true } : null); IPublishingResiliencePolicies publishingResiliencePolicies = ctx.GetService <IPublishingResiliencePolicies>(); return(new PublishedFundingBulkRepository(publishingResiliencePolicies, publishingEngineOptions, calcsCosmosRepository)); }); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { BlobStorageOptions storageSettings = new BlobStorageOptions(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "publishedproviderversions"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(storageSettings); return(new BlobClient(blobContainerRepository)); }); builder.AddCaching(Configuration); builder.AddSearch(Configuration); builder .AddSingleton <ISearchRepository <PublishedProviderIndex>, SearchRepository <PublishedProviderIndex> >(); builder .AddSingleton <ISearchRepository <PublishedFundingIndex>, SearchRepository <PublishedFundingIndex> >(); builder .AddSingleton <IPublishedProviderProfilingService, PublishedProviderProfilingService>() .AddSingleton <IPublishedProviderErrorDetection, PublishedProviderErrorDetection>() .AddSingleton <IErrorDetectionStrategyLocator, ErrorDetectionStrategyLocator>() .AddSingleton <IDetectPublishedProviderErrors, FundingLineValueProfileMismatchErrorDetector>() .AddSingleton <IProfilingService, ProfilingService>() .AddSingleton <IHealthChecker, ProfilingService>() .AddSingleton <IPublishedProviderVersioningService, PublishedProviderVersioningService>(); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Publishing"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Publishing"); builder.AddLogging("CalculateFunding.Api.Publishing"); builder.AddTelemetry(); builder.AddServiceBus(Configuration, "publishing"); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddPolicySettings(Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); builder.AddHttpCachingMvc(); builder.AddQueryProviderAndExtractorForViewModelMvc <PublishedProviderFundingStructure, PublishedProviderFundingStructureTimedEtagProvider, PublishedProviderFundingStructureTimedEtagExtractor>(false); builder.AddPublishingServices(Configuration); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddProvidersInterServiceClient(Configuration); builder.AddCalculationsInterServiceClient(Configuration); builder.AddProfilingInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddPoliciesInterServiceClient(Configuration); builder.AddFundingDataServiceInterServiceClient(Configuration); builder.AddFeatureToggling(Configuration); 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(); Configuration.Bind("CosmosDbSettings", settings); settings.ContainerName = "publishedfunding"; return(new PublishedFundingUndoCosmosRepository(ctx.GetService <IPublishingResiliencePolicies>(), new CosmosRepository(settings))); }); builder.AddSingleton <IPublishedFundingUndoBlobStoreRepository>(ctx => { BlobStorageOptions settings = new BlobStorageOptions(); Configuration.Bind("AzureStorageSettings", settings); settings.ContainerName = "publishedproviderversions"; IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(settings); return(new PublishedFundingUndoBlobStoreRepository(new BlobClient(blobContainerRepository), ctx.GetService <IPublishingResiliencePolicies>(), ctx.GetService <ILogger>())); }); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder .AddSingleton <LocalIBlobClient, LocalBlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "publishedfunding"; return(new LocalBlobClient(storageSettings)); }); MapperConfiguration resultsConfig = new MapperConfiguration(c => { c.AddProfile <PublishingServiceMappingProfile>(); }); builder.AddSingleton(resultsConfig.CreateMapper()); builder.AddSingleton <IPublishingResiliencePolicies>(ctx => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedFundingRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(), PublishedProviderVersionRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProfilingApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedIndexSearchResiliencePolicy = PublishedIndexSearchResiliencePolicy.GeneratePublishedIndexSearch(), PublishedProviderSearchRepository = PublishedIndexSearchResiliencePolicy.GeneratePublishedIndexSearch(), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), FundingStreamPaymentDatesRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy) }); }); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); builder.AddSingleton <IPublishedProviderFundingCountProcessor, PublishedProviderFundingCountProcessor>(); builder.AddSingleton <IPublishedProviderFundingCsvDataProcessor, PublishedProviderFundingCsvDataProcessor>(); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Publishing Microservice API"); } }
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 <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()); }