public static IServiceCollection AddCalcsResiliencePolicies(this IServiceCollection serviceCollection) { serviceCollection.AddSingleton <ICalcsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); return(serviceCollection); }
private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ResiliencePolicies resiliencePolicies = new ResiliencePolicies() { CalculationProviderResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderProfilingRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderCalculationResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), PublishedProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderCalculationResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ProviderChangesRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
public static IServiceProvider BuildServiceProvider() { IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddApplicationInsightsTelemetryClient(_configuration, "CalculateFunding.Migrations.PublishedProviderPopulateReleased"); serviceCollection.AddLogging(serviceName: "CalculateFunding.Migrations.PublishedProviderPopulateReleased"); serviceCollection.AddPolicySettings(_configuration); serviceCollection.AddSingleton <ICosmosRepository>(ctx => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); _configuration.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "publishedfunding"; return(new CosmosRepository(cosmosDbSettings)); }); serviceCollection.AddSingleton <IPublishingResiliencePolicies>(ctx => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers .GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { PublishedProviderVersionRepository = ResiliencePolicyHelpers .GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); serviceCollection.AddTransient <IPublishedProviderMigration, PublishedProviderMigration>(); return(serviceCollection.BuildServiceProvider()); }
internal IServiceCollection ConfigureServices(IServiceCollection builder) { builder.AddTransient <IPublishedProviderContentsGenerator, PublishedProviderContentsGenerator>(); builder.AddTransient <IPublishedFundingContentsGenerator, PublishedFundingContentsGenerator>(); builder.AddTransient <Providers.v1.ProviderDocumentGenerator>(); builder.AddTransient <Providers.v2.ProviderDocumentGenerator>(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Generators.NavFeed"); builder.AddLogging("CalculateFunding.Generators.NavFeed"); builder.AddProvidersInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); builder.AddSingleton <IOrganisationGroupResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new OrganisationGroupResiliencePolicies { ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); return(builder); }
private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); ResiliencePolicies resiliencePolicies = new ResiliencePolicies { CalculationResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderVersionRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedFundingRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProfilingApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), FundingFeedSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), PublishedFundingBlobRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), PublishedIndexSearchResiliencePolicy = PublishedIndexSearchResiliencePolicy.GeneratePublishedIndexSearch(), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
private static OrganisationGroupResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); OrganisationGroupResiliencePolicies resiliencePolicies = new OrganisationGroupResiliencePolicies { ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
private static ProvidersResiliencePolicies CreateResiliencePolicies(AsyncBulkheadPolicy totalNetworkRequestsPolicy) { return(new ProvidersResiliencePolicies { ProviderVersionsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ProviderVersionMetadataRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), BlobRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(), FundingDataZoneApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }
private static CalculatorResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); CalculatorResiliencePolicies resiliencePolicies = new CalculatorResiliencePolicies() { ProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderSourceDatasetsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), Messenger = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }
private static PolicyResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new PolicyResiliencePolicies { PolicyRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), FundingSchemaRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), FundingTemplateRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), TemplatesSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), TemplatesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }
private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }
private static DatasetsResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings) { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new DatasetsResiliencePolicies { SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProviderRepository = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), ProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), DatasetRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), DatasetSearchService = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), DatasetDefinitionSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }
private static ResiliencePolicies CreateResiliencePolicies(AsyncPolicy totalNetworkRequestsPolicy) { return(new ResiliencePolicies { CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), GraphApiClientPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalcEngineApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }
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 <OnEditSpecificationEvent>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IUserService, UserService>() .AddSingleton <IHealthChecker, UserService>(); builder .AddSingleton <IFundingStreamPermissionService, FundingStreamPermissionService>() .AddSingleton <IHealthChecker, FundingStreamPermissionService>(); builder.AddSingleton <IValidator <UserCreateModel>, UserCreateModelValidator>(); builder.AddSingleton <IUserRepository, UserRepository>((ctx) => { CosmosDbSettings usersDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", usersDbSettings); usersDbSettings.ContainerName = "users"; CosmosRepository usersCosmosRepostory = new CosmosRepository(usersDbSettings); return(new UserRepository(usersCosmosRepostory)); }); MapperConfiguration mappingConfig = new MapperConfiguration(c => c.AddProfile <UsersMappingProfile>()); builder.AddSingleton(mappingConfig.CreateMapper()); builder.AddSingleton <IVersionRepository <FundingStreamPermissionVersion>, VersionRepository <FundingStreamPermissionVersion> >((ctx) => { CosmosDbSettings versioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", versioningDbSettings); versioningDbSettings.ContainerName = "users"; CosmosRepository versioningRepository = new CosmosRepository(versioningDbSettings); return(new VersionRepository <FundingStreamPermissionVersion>(versioningRepository, new NewVersionBuilderFactory <FundingStreamPermissionVersion>())); }); builder.AddPolicySettings(config); builder.AddSingleton <IUsersResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new UsersResiliencePolicies { FundingStreamPermissionVersionRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), SpecificationApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), UserRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), }); }); builder.AddCaching(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Users"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Users"); builder.AddLogging("CalculateFunding.Functions.Users"); builder.AddServiceBus(config, "users"); builder.AddTelemetry(); builder.AddSpecificationsInterServiceClient(config); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder.AddSingleton <OnCosmosDbDiagnosticsReceived>(); builder.AddSingleton <OnScaleUpCosmosDbCollection>(); builder.AddSingleton <OnIncrementalScaleDownCosmosDbCollection>(); builder.AddSingleton <OnScaleDownCosmosDbCollection>(); builder.AddSingleton <ICosmosDbScalingRepositoryProvider, CosmosDbScalingRepositoryProvider>(); builder.AddSingleton <ICosmosDbScalingService, CosmosDbScalingService>(); builder.AddSingleton <ICosmosDbScalingRequestModelBuilder, CosmosDbScalingRequestModelBuilder>(); builder.AddSingleton <ICosmosDbThrottledEventsFilter, CosmosDbThrottledEventsFilter>(); builder.AddSingleton <CalculationProviderResultsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "calculationresults"; CosmosRepository cosmosRepostory = new CosmosRepository(cosmosDbSettings); return(new CalculationProviderResultsScalingRepository(cosmosRepostory)); }); builder.AddSingleton <ProviderSourceDatasetsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "providerdatasets"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new ProviderSourceDatasetsScalingRepository(cosmosRepository)); }); builder.AddSingleton <CalculationsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "calcs"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new CalculationsScalingRepository(cosmosRepository)); }); builder.AddSingleton <JobsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "jobs"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new JobsScalingRepository(cosmosRepository)); }); builder.AddSingleton <DatasetAggregationsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "datasetaggregations"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new DatasetAggregationsScalingRepository(cosmosRepository)); }); builder.AddSingleton <DatasetsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "datasets"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new DatasetsScalingRepository(cosmosRepository)); }); builder.AddSingleton <ProfilingScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "profiling"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new ProfilingScalingRepository(cosmosRepository)); }); builder.AddSingleton <SpecificationsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "specs"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new SpecificationsScalingRepository(cosmosRepository)); }); builder.AddSingleton <TestResultsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "testresults"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new TestResultsScalingRepository(cosmosRepository)); }); builder.AddSingleton <TestsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "tests"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new TestsScalingRepository(cosmosRepository)); }); builder.AddSingleton <UsersScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "users"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new UsersScalingRepository(cosmosRepository)); }); builder.AddSingleton <PublishedProviderResultsScalingRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "publishedproviderresults"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new PublishedProviderResultsScalingRepository(cosmosRepository)); }); builder.AddSingleton <ICosmosDbScalingConfigRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.CollectionName = "cosmosscalingconfig"; CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings); return(new CosmosDbScalingConfigRepository(cosmosRepository)); }); builder.AddCaching(config); builder.AddJobsInterServiceClient(config); builder.AddServiceBus(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.CosmosDbScaling"); builder.AddLogging("CalculateFunding.Functions.CosmosDbScaling", config); builder.AddTelemetry(); builder.AddFeatureToggling(config); builder.AddSingleton <ICosmosDbScallingResilliencePolicies>(m => { PolicySettings policySettings = builder.GetPolicySettings(config); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); CosmosDbScallingResilliencePolicies resiliencePolicies = new CosmosDbScallingResilliencePolicies() { ScalingRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ScalingConfigRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }); return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder.AddSingleton <OnDataDefinitionChanges>(); builder.AddSingleton <OnEditCaluclationEvent>(); builder.AddSingleton <OnEditSpecificationEvent>(); builder.AddSingleton <IScenariosRepository, ScenariosRepository>(); builder.AddSingleton <IScenariosService, ScenariosService>(); builder.AddSingleton <IScenariosSearchService, ScenariosSearchService>(); builder .AddSingleton <IValidator <CreateNewTestScenarioVersion>, CreateNewTestScenarioVersionValidator>(); builder .AddSingleton <ISpecificationsRepository, SpecificationsRepository>(); builder .AddSingleton <IBuildProjectRepository, BuildProjectRepository>(); builder .AddSingleton <ICalcsRepository, CalcsRepository>(); builder .AddSingleton <ICancellationTokenProvider, InactiveCancellationTokenProvider>(); builder .AddSingleton <IDatasetRepository, DatasetRepository>(); builder .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); builder.AddSingleton <IVersionRepository <TestScenarioVersion>, VersionRepository <TestScenarioVersion> >((ctx) => { CosmosDbSettings scenariosVersioningDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", scenariosVersioningDbSettings); scenariosVersioningDbSettings.CollectionName = "tests"; CosmosRepository resultsRepostory = new CosmosRepository(scenariosVersioningDbSettings); return(new VersionRepository <TestScenarioVersion>(resultsRepostory)); }); builder.AddCalcsInterServiceClient(config); builder.AddSpecificationsInterServiceClient(config); builder.AddDatasetsInterServiceClient(config); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") { builder.AddCosmosDb(config, "tests"); } else { builder.AddCosmosDb(config); } builder.AddJobsInterServiceClient(config); builder.AddSearch(config); builder.AddServiceBus(config); builder.AddCaching(config); builder.AddApplicationInsights(config, "CalculateFunding.Functions.Scenarios"); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Scenarios"); builder.AddLogging("CalculateFunding.Functions.Scenarios"); builder.AddTelemetry(); builder.AddFeatureToggling(config); builder.AddPolicySettings(config); builder.AddSingleton <IScenariosResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); Policy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new ScenariosResiliencePolicies() { CalcsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ScenariosRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy) }); }); return(builder.BuildServiceProvider()); }
public static IServiceProvider BuildServiceProvider(string collectionName) { IServiceCollection builder = new ServiceCollection(); builder.AddApplicationInsightsTelemetryClient(Configuration, ServiceName); builder.AddLogging(serviceName: ServiceName); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddPolicySettings(Configuration); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <IJobTracker, JobTracker>(); builder.AddJobsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddServiceBus(Configuration); builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <ICosmosRepository>(ctx => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = collectionName; return(new CosmosRepository(cosmosDbSettings)); }); builder.AddSingleton <IPublishingResiliencePolicies>(ctx => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers .GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { JobsApiClient = ResiliencePolicyHelpers .GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedFundingRepository = ResiliencePolicyHelpers .GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedIndexSearchResiliencePolicy = ResiliencePolicyHelpers .GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers .GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddSingleton <IJobManagementResiliencePolicies>(ctx => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers .GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies { JobsApiClient = ResiliencePolicyHelpers .GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddSingleton <IPublishedFundingUndoCosmosRepository, PublishedFundingUndoCosmosRepository>(); builder.AddSingleton <IPublishedFundingUndoBlobStoreRepository>(ctx => { BlobStorageOptions settings = new BlobStorageOptions(); Configuration.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 <IPublishedFundingUndoJobCreation, PublishedFundingUndoJobCreation>(); builder.AddSingleton <IPublishedFundingUndoTaskFactoryLocator, PublishedFundingUndoTaskFactoryLocator>(); builder.AddSingleton <IDsgRollBackCosmosDocumentsJob, DsgRollBackCosmosDocumentsJob>(); builder.AddSingleton <IPublishedFundingUndoTaskFactory, DsgRollBackTaskFactory>(); builder.AddSingleton <IRollBackDsg, RollBackDsg>(); 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 <OnTestSpecificationProviderResultsCleanup>(); builder.AddScoped <OnEditSpecificationEvent>(); builder.AddScoped <OnTestExecution>(); builder.AddScoped <OnDeleteTestResults>(); builder.AddScoped <OnDeleteTestResultsFailure>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IGherkinParserService, GherkinParserService>(); builder .AddSingleton <IGherkinParser, GherkinParser>(); builder .AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>(); builder .AddSingleton <IStepParserFactory, StepParserFactory>(); builder.AddSingleton <ITestResultsRepository, TestResultsRepository>((ctx) => { CosmosDbSettings testResultsDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", testResultsDbSettings); testResultsDbSettings.ContainerName = "testresults"; CosmosRepository providersCosmosRepostory = new CosmosRepository(testResultsDbSettings); EngineSettings engineSettings = ctx.GetService <EngineSettings>(); ILogger logger = ctx.GetService <ILogger>(); return(new TestResultsRepository(providersCosmosRepostory, logger, engineSettings)); }); builder .AddSingleton <IScenariosRepository, ScenariosRepository>(); builder .AddScoped <ITestEngineService, TestEngineService>(); builder .AddSingleton <ITestEngine, Services.TestRunner.TestEngine>(); builder .AddSingleton <IGherkinExecutor, GherkinExecutor>(); builder .AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>((ctx) => { CosmosDbSettings providersDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", providersDbSettings); providersDbSettings.ContainerName = "providerdatasets"; CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings); EngineSettings engineSettings = ctx.GetService <EngineSettings>(); return(new ProviderSourceDatasetsRepository(providersCosmosRepostory, engineSettings)); }); builder.AddSingleton <IProviderResultsRepository, ProviderResultsRepository>((ctx) => { CosmosDbSettings providersDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", providersDbSettings); providersDbSettings.ContainerName = "calculationresults"; CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings); return(new ProviderResultsRepository(providersCosmosRepostory)); }); builder.AddSingleton <ITestResultsSearchService, TestResultsSearchService>(); builder.AddSingleton <ITestResultsCountsService, TestResultsCountsService>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <IDeadletterService, DeadletterService>(); MapperConfiguration mappingConfiguration = new MapperConfiguration(c => { c.AddProfile <TestEngineMappingProfile>(); }); builder .AddSingleton(mappingConfiguration.CreateMapper()); builder.AddScoped <ITestResultsService, TestResultsService>(); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <TestScenarioResultIndex>, SearchRepository <TestScenarioResultIndex> >(); builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddScenariosInterServiceClient(config); builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddProvidersInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddCaching(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.TestEngine", TelemetryChannelType.Sync); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.TestEngine"); builder.AddLogging("CalculateFunding.Functions.TestEngine"); builder.AddServiceBus(config, "testengine"); builder.AddTelemetry(); builder.AddEngineSettings(config); builder.AddPolicySettings(config); builder.AddFeatureToggling(config); builder.AddSingleton((Func <IServiceProvider, ITestRunnerResiliencePolicies>)((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); AsyncPolicy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); ResiliencePolicies resiliencePolicies = new ResiliencePolicies() { CalculationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProviderRepository = redisPolicy, ProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderSourceDatasetsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ScenariosRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(new[] { totalNetworkRequestsPolicy, redisPolicy }), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), TestResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), TestResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); })); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); 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.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder .AddSingleton <IUserService, UserService>() .AddSingleton <IHealthChecker, UserService>(); builder .AddSingleton <IFundingStreamPermissionService, FundingStreamPermissionService>() .AddSingleton <IHealthChecker, FundingStreamPermissionService>(); builder.AddSingleton <IValidator <UserCreateModel>, UserCreateModelValidator>(); builder.AddSingleton <IUserRepository, UserRepository>((ctx) => { CosmosDbSettings usersDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", usersDbSettings); usersDbSettings.ContainerName = "users"; CosmosRepository usersCosmosRepostory = new CosmosRepository(usersDbSettings); return(new UserRepository(usersCosmosRepostory)); }); MapperConfiguration mappingConfig = new MapperConfiguration(c => c.AddProfile <UsersMappingProfile>()); builder.AddSingleton(mappingConfig.CreateMapper()); builder.AddSingleton <IVersionRepository <FundingStreamPermissionVersion>, VersionRepository <FundingStreamPermissionVersion> >((ctx) => { CosmosDbSettings versioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", versioningDbSettings); versioningDbSettings.ContainerName = "users"; CosmosRepository versioningRepository = new CosmosRepository(versioningDbSettings); return(new VersionRepository <FundingStreamPermissionVersion>(versioningRepository, new NewVersionBuilderFactory <FundingStreamPermissionVersion>())); }); builder.AddPolicySettings(Configuration); builder.AddSingleton <IUsersResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new UsersResiliencePolicies { FundingStreamPermissionVersionRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), SpecificationApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), UserRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), }); }); builder.AddCaching(Configuration); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Users"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Users"); builder.AddLogging("CalculateFunding.Api.Users"); builder.AddTelemetry(); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); builder.AddSpecificationsInterServiceClient(Configuration); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Users Microservice API"); } }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <IScenariosRepository, ScenariosRepository>(); builder .AddSingleton <IScenariosService, ScenariosService>() .AddSingleton <IHealthChecker, ScenariosService>(); builder .AddSingleton <IScenariosSearchService, ScenariosSearchService>() .AddSingleton <IHealthChecker, ScenariosSearchService>(); builder .AddSingleton <IValidator <CreateNewTestScenarioVersion>, CreateNewTestScenarioVersionValidator>(); builder .AddSingleton <ISpecificationsRepository, SpecificationsRepository>(); builder .AddSingleton <IBuildProjectRepository, BuildProjectRepository>(); builder .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); builder.AddSingleton <IVersionRepository <TestScenarioVersion>, VersionRepository <TestScenarioVersion> >((ctx) => { CosmosDbSettings scenariosVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", scenariosVersioningDbSettings); scenariosVersioningDbSettings.CollectionName = "tests"; CosmosRepository resultsRepostory = new CosmosRepository(scenariosVersioningDbSettings); return(new VersionRepository <TestScenarioVersion>(resultsRepostory)); }); builder .AddSingleton <ICalcsRepository, CalcsRepository>(); builder .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>(); builder.AddSingleton <IDatasetRepository, DatasetRepository>(); builder .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); builder.AddUserProviderFromRequest(); builder.AddCalcsInterServiceClient(Configuration); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddDatasetsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddCosmosDb(Configuration); builder.AddSearch(Configuration); builder.AddServiceBus(Configuration); builder.AddCaching(Configuration); builder.AddFeatureToggling(Configuration); builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Scenarios"); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Scenarios"); builder.AddLogging("CalculateFunding.Api.Scenarios"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); builder.AddPolicySettings(Configuration); builder.AddSingleton <IScenariosResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); Policy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new ScenariosResiliencePolicies() { CalcsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); }
public void RegisterComponents(IServiceCollection builder) { builder .AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder .AddSingleton <ICalculationService, CalculationService>() .AddSingleton <IHealthChecker, CalculationService>(); builder .AddSingleton <ICalculationCodeReferenceUpdate, CalculationCodeReferenceUpdate>() .AddSingleton <ITokenChecker, TokenChecker>(); builder .AddSingleton <ICalculationsSearchService, CalculationSearchService>() .AddSingleton <IHealthChecker, CalculationSearchService>(); builder .AddSingleton <IValidator <Calculation>, CalculationModelValidator>(); builder .AddSingleton <IPreviewService, PreviewService>() .AddSingleton <IHealthChecker, PreviewService>(); builder .AddSingleton <ICompilerFactory, CompilerFactory>(); builder .AddSingleton <CSharpCompiler>() .AddSingleton <VisualBasicCompiler>() .AddSingleton <VisualBasicSourceFileGenerator>(); builder .AddSingleton <ISourceFileGeneratorProvider, SourceFileGeneratorProvider>(); builder .AddSingleton <IValidator <PreviewRequest>, PreviewRequestModelValidator>(); builder .AddSingleton <IProviderResultsRepository, ProviderResultsRepository>() .AddSingleton <IHealthChecker, ProviderResultsRepository>(); builder .AddSingleton <ISpecificationRepository, SpecificationRepository>(); builder .AddSingleton <IBuildProjectsService, BuildProjectsService>() .AddSingleton <IHealthChecker, BuildProjectsService>(); builder .AddSingleton <IBuildProjectsRepository, BuildProjectsRepository>() .AddSingleton <IHealthChecker, BuildProjectsRepository>(); builder .AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>(); builder .AddSingleton <IDatasetRepository, DatasetRepository>(); builder.AddSingleton <ISourceCodeService, SourceCodeService>(); builder .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); builder.AddSingleton <ISourceFileRepository, SourceFileRepository>((ctx) => { BlobStorageOptions blobStorageOptions = new BlobStorageOptions(); Configuration.Bind("CommonStorageSettings", blobStorageOptions); blobStorageOptions.ContainerName = "source"; return(new SourceFileRepository(blobStorageOptions)); }); builder.AddSingleton <IVersionRepository <CalculationVersion>, VersionRepository <CalculationVersion> >((ctx) => { CosmosDbSettings calcsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calcsVersioningDbSettings); calcsVersioningDbSettings.CollectionName = "calcs"; CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings); return(new VersionRepository <CalculationVersion>(resultsRepostory)); }); builder .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>(); builder.AddUserProviderFromRequest(); builder.AddCosmosDb(Configuration); builder.AddSearch(Configuration); builder.AddServiceBus(Configuration); builder.AddResultsInterServiceClient(Configuration); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddDatasetsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddCaching(Configuration); builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Calcs"); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Calcs"); builder.AddLogging("CalculateFunding.Api.Calcs"); builder.AddTelemetry(); builder.AddEngineSettings(Configuration); builder.AddFeatureToggling(Configuration); builder.AddPolicySettings(Configuration); builder.AddSingleton <ICalcsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies { CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); }
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"); } }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>(); builder .AddSingleton <IResultsService, ResultsService>() .AddSingleton <IHealthChecker, ResultsService>(); builder .AddSingleton <IPublishedResultsService, PublishedResultsService>() .AddSingleton <IHealthChecker, PublishedResultsService>(); builder .AddSingleton <IResultsSearchService, ResultsSearchService>() .AddSingleton <IHealthChecker, ResultsSearchService>(); builder .AddSingleton <IProviderCalculationResultsSearchService, ProviderCalculationResultsSearchService>() .AddSingleton <IHealthChecker, ProviderCalculationResultsSearchService>(); builder .AddSingleton <ICalculationProviderResultsSearchService, CalculationProviderResultsSearchService>() .AddSingleton <IHealthChecker, CalculationProviderResultsSearchService>(); builder.AddSingleton <IProviderImportMappingService, ProviderImportMappingService>(); builder .AddSingleton <IAllocationNotificationsFeedsSearchService, AllocationNotificationsFeedsSearchService>(); builder.AddSingleton <IProviderVariationAssemblerService, ProviderVariationAssemblerService>(); MapperConfiguration resultsConfig = new MapperConfiguration(c => { c.AddProfile <DatasetsMappingProfile>(); c.AddProfile <ResultServiceMappingProfile>(); }); builder .AddSingleton(resultsConfig.CreateMapper()); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>((ctx) => { CosmosDbSettings calssDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calssDbSettings); calssDbSettings.CollectionName = "calculationresults"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calssDbSettings); return(new CalculationResultsRepository(calcsCosmosRepostory)); }); builder.AddSingleton <IProviderSourceDatasetRepository, ProviderSourceDatasetRepository>((ctx) => { CosmosDbSettings provDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", provDbSettings); provDbSettings.CollectionName = "providerdatasets"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(provDbSettings); return(new ProviderSourceDatasetRepository(calcsCosmosRepostory)); }); builder.AddSingleton <IPublishedProviderResultsRepository, PublishedProviderResultsRepository>((ctx) => { CosmosDbSettings resultsDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", resultsDbSettings); resultsDbSettings.CollectionName = "publishedproviderresults"; CosmosRepository resultsRepostory = new CosmosRepository(resultsDbSettings); return(new PublishedProviderResultsRepository(resultsRepostory)); }); builder.AddSingleton <IProviderChangesRepository, ProviderChangesRepository>((ctx) => { CosmosDbSettings resultsDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", resultsDbSettings); resultsDbSettings.CollectionName = "publishedproviderchanges"; CosmosRepository resultsRepostory = new CosmosRepository(resultsDbSettings); ILogger logger = ctx.GetService <ILogger>(); return(new ProviderChangesRepository(resultsRepostory, logger)); }); builder.AddSingleton <IProviderCalculationResultsReIndexerService, ProviderCalculationResultsReIndexerService>(); builder.AddSingleton <IValidator <MasterProviderModel>, MasterProviderModelValidator>(); builder .AddSingleton <ISpecificationsRepository, SpecificationsRepository>(); builder .AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder .AddSingleton <IPublishedProviderResultsAssemblerService, PublishedProviderResultsAssemblerService>(); builder.AddSingleton <IPublishedProviderResultsSettings, PublishedProviderResultsSettings>((ctx) => { PublishedProviderResultsSettings settings = new PublishedProviderResultsSettings(); Configuration.Bind("PublishedProviderResultsSettings", settings); return(settings); }); builder.AddSingleton <IVersionRepository <PublishedAllocationLineResultVersion>, VersionRepository <PublishedAllocationLineResultVersion> >((ctx) => { CosmosDbSettings versioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", versioningDbSettings); versioningDbSettings.CollectionName = "publishedproviderresults"; CosmosRepository resultsRepostory = new CosmosRepository(versioningDbSettings); return(new VersionRepository <PublishedAllocationLineResultVersion>(resultsRepostory)); }); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "datasets"; return(new BlobClient(storageSettings)); }); builder.AddUserProviderFromRequest(); builder.AddSearch(Configuration); builder.AddServiceBus(Configuration); builder.AddCaching(Configuration); builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Results"); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Results"); builder.AddLogging("CalculateFunding.Api.Results"); builder.AddTelemetry(); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddCalcsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); builder.AddHttpContextAccessor(); builder.AddFeatureToggling(Configuration); builder.AddSingleton <IPublishedAllocationLineLogicalResultVersionService, PublishedAllocationLineLogicalResultVersionService>(); builder.AddSingleton <IResultsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies() { CalculationProviderResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), SpecificationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), AllocationNotificationFeedSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ProviderProfilingRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderCalculationResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), PublishedProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderChangesRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderCalculationResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), CsvBlobPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHealthCheckMiddleware(); ServiceProvider = builder.BuildServiceProvider(); }
public void RegisterComponents(IServiceCollection builder) { builder .AddSingleton <IDefinitionsService, DefinitionsService>() .AddSingleton <IHealthChecker, DefinitionsService>(); builder .AddSingleton <IDatasetService, DatasetService>() .AddSingleton <IHealthChecker, DatasetService>(); builder .AddSingleton <IProcessDatasetService, ProcessDatasetService>() .AddSingleton <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 <CreateDefinitionSpecificationRelationshipModel>, CreateDefinitionSpecificationRelationshipModelValidator>(); builder .AddSingleton <IExcelWriter <DatasetDefinition>, DataDefinitionExcelWriter>(); builder .AddSingleton <IValidator <ExcelPackage>, DatasetWorksheetValidator>(); builder .AddSingleton <IDefinitionChangesDetectionService, DefinitionChangesDetectionService>(); builder .AddSingleton <IDatasetDefinitionNameChangeProcessor, DatasetDefinitionNameChangeProcessor>(); builder .AddSingleton <IBlobClient, BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); Configuration.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "datasets"; return(new BlobClient(storageSettings)); }); builder.AddSingleton <IProvidersResultsRepository, ProvidersResultsRepository>((ctx) => { CosmosDbSettings dbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", dbSettings); dbSettings.CollectionName = "providerdatasets"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(dbSettings); return(new ProvidersResultsRepository(calcsCosmosRepostory)); }); builder.AddSingleton <IDatasetsAggregationsRepository, DatasetsAggregationsRepository>((ctx) => { CosmosDbSettings dbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", dbSettings); dbSettings.CollectionName = "datasetaggregations"; CosmosRepository aggsCosmosRepostory = new CosmosRepository(dbSettings); return(new DatasetsAggregationsRepository(aggsCosmosRepostory)); }); builder.AddSingleton <IVersionRepository <ProviderSourceDatasetVersion>, VersionRepository <ProviderSourceDatasetVersion> >((ctx) => { CosmosDbSettings ProviderSourceDatasetVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", ProviderSourceDatasetVersioningDbSettings); ProviderSourceDatasetVersioningDbSettings.CollectionName = "providersources"; CosmosRepository cosmosRepository = new CosmosRepository(ProviderSourceDatasetVersioningDbSettings); return(new VersionRepository <ProviderSourceDatasetVersion>(cosmosRepository)); }); builder.AddSingleton <IDatasetRepository, DataSetsRepository>(); builder.AddSingleton <IDatasetSearchService, DatasetSearchService>() .AddSingleton <IHealthChecker, DatasetSearchService>(); builder.AddSingleton <IDatasetDefinitionSearchService, DatasetDefinitionSearchService>(); builder .AddSingleton <IDefinitionSpecificationRelationshipService, DefinitionSpecificationRelationshipService>() .AddSingleton <IHealthChecker, DefinitionSpecificationRelationshipService>(); builder .AddSingleton <ISpecificationsRepository, SpecificationsRepository>(); builder .AddSingleton <IExcelDatasetReader, ExcelDatasetReader>(); builder .AddSingleton <IProviderService, ProviderService>(); builder .AddSingleton <ICalcsRepository, CalcsRepository>(); builder .AddSingleton <IResultsRepository, ResultsRepository>(); builder .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>(); MapperConfiguration dataSetsConfig = new MapperConfiguration(c => { c.AddProfile <DatasetsMappingProfile>(); c.AddProfile <ProviderMappingProfile>(); }); builder .AddSingleton(dataSetsConfig.CreateMapper()); builder.AddUserProviderFromRequest(); builder.AddCalcsInterServiceClient(Configuration); builder.AddResultsInterServiceClient(Configuration); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddCosmosDb(Configuration); builder.AddSearch(Configuration); builder.AddServiceBus(Configuration); builder.AddCaching(Configuration); builder.AddFeatureToggling(Configuration); builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Datasets"); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Datasets"); builder.AddLogging("CalculateFunding.Api.Datasets"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddPolicySettings(Configuration); builder.AddHttpContextAccessor(); builder.AddSingleton <IDatasetsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); Policy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new DatasetsResiliencePolicies() { SpecificationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProviderRepository = redisPolicy, ProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), DatasetRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), DatasetSearchService = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), DatasetDefinitionSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), BlobClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddTransient <IValidator <DatasetUploadValidationModel>, DatasetItemValidator>(); builder.AddSingleton <IProviderService, ProviderService>(); builder.AddHealthCheckMiddleware(); }
public void RegisterComponents(IServiceCollection builder) { builder.AddFeatureToggling(Configuration); // Register v1 services builder .AddSingleton <V1.Interfaces.IAllocationNotificationFeedsService, V1.Services.AllocationNotificationFeedsService>(); builder .AddSingleton <V1.Interfaces.IProviderResultsService, V1.Services.ProviderResultsService>(); builder .AddSingleton <V1.Interfaces.IAllocationsService, V1.Services.AllocationsService>(); builder .AddSingleton <V1.Interfaces.ITimePeriodsService, V1.Services.TimePeriodsService>(); builder .AddSingleton <V1.Interfaces.IFundingStreamService, V1.Services.FundingStreamService>(); // Register v2 services builder .AddSingleton <V2.Interfaces.IAllocationNotificationFeedsService, V2.Services.AllocationNotificationFeedsService>(); builder .AddSingleton <V2.Interfaces.IProviderResultsService, V2.Services.ProviderResultsService>(); builder .AddSingleton <V2.Interfaces.IAllocationsService, V2.Services.AllocationsService>(); builder .AddSingleton <V2.Interfaces.ITimePeriodsService, V2.Services.TimePeriodsService>(); builder .AddSingleton <V2.Interfaces.IFundingStreamService, V2.Services.FundingStreamService>(); // Register dependencies builder .AddSingleton <IAllocationNotificationsFeedsSearchService, AllocationNotificationsFeedsSearchService>() .AddSingleton <IHealthChecker, AllocationNotificationsFeedsSearchService>(); builder .AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>(); builder .AddSingleton <IPublishedResultsService, PublishedResultsService>() .AddSingleton <IHealthChecker, PublishedResultsService>(); builder .AddSingleton <ICalculationProviderResultsSearchService, CalculationProviderResultsSearchService>() .AddSingleton <IHealthChecker, CalculationProviderResultsSearchService>(); builder.AddSingleton <IProviderImportMappingService, ProviderImportMappingService>(); builder .AddSingleton <IAllocationNotificationsFeedsSearchService, AllocationNotificationsFeedsSearchService>(); MapperConfiguration resultsConfig = new MapperConfiguration(c => { c.AddProfile <DatasetsMappingProfile>(); c.AddProfile <ExternalApiMappingProfile>(); }); builder .AddSingleton(resultsConfig.CreateMapper()); builder.AddSingleton <IVersionRepository <SpecificationVersion>, VersionRepository <SpecificationVersion> >((ctx) => { CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", specsVersioningDbSettings); specsVersioningDbSettings.CollectionName = "specs"; CosmosRepository resultsRepostory = new CosmosRepository(specsVersioningDbSettings); return(new VersionRepository <SpecificationVersion>(resultsRepostory)); }); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>((ctx) => { CosmosDbSettings calssDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", calssDbSettings); calssDbSettings.CollectionName = "calculationresults"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calssDbSettings); return(new CalculationResultsRepository(calcsCosmosRepostory)); }); builder.AddSingleton <IProviderSourceDatasetRepository, ProviderSourceDatasetRepository>((ctx) => { CosmosDbSettings provDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", provDbSettings); provDbSettings.CollectionName = "providerdatasets"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(provDbSettings); return(new ProviderSourceDatasetRepository(calcsCosmosRepostory)); }); builder.AddSingleton <IPublishedProviderResultsRepository, PublishedProviderResultsRepository>((ctx) => { CosmosDbSettings resultsDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", resultsDbSettings); resultsDbSettings.CollectionName = "publishedproviderresults"; CosmosRepository resultsRepostory = new CosmosRepository(resultsDbSettings); return(new PublishedProviderResultsRepository(resultsRepostory)); }); builder.AddSingleton <IProviderChangesRepository, ProviderChangesRepository>((ctx) => { CosmosDbSettings repoSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", repoSettings); repoSettings.CollectionName = "publishedproviderchanges"; CosmosRepository repo = new CosmosRepository(repoSettings); ILogger logger = ctx.GetRequiredService <ILogger>(); return(new ProviderChangesRepository(repo, logger)); }); builder .AddSingleton <ISpecificationsRepository, SpecificationsRepository>(); builder .AddSingleton <IPublishedProviderResultsAssemblerService, PublishedProviderResultsAssemblerService>(); builder.AddSingleton <Services.Specs.Interfaces.ISpecificationsRepository, Services.Specs.SpecificationsRepository>( ctx => { CosmosDbSettings specRepoDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", specRepoDbSettings); specRepoDbSettings.CollectionName = "specs"; CosmosRepository cosmosRepository = new CosmosRepository(specRepoDbSettings); return(new Services.Specs.SpecificationsRepository(cosmosRepository)); }); builder.AddSingleton <IVersionRepository <PublishedAllocationLineResultVersion>, VersionRepository <PublishedAllocationLineResultVersion> >((ctx) => { CosmosDbSettings versioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", versioningDbSettings); versioningDbSettings.CollectionName = "publishedproviderresults"; CosmosRepository resultsRepostory = new CosmosRepository(versioningDbSettings); return(new VersionRepository <PublishedAllocationLineResultVersion>(resultsRepostory)); }); builder.AddSingleton <IPublishedAllocationLineLogicalResultVersionService, PublishedAllocationLineLogicalResultVersionService>(); builder.AddSingleton <IPublishedProviderResultsSettings, PublishedProviderResultsSettings>((ctx) => { PublishedProviderResultsSettings settings = new PublishedProviderResultsSettings(); Configuration.Bind("PublishedProviderResultsSettings", settings); return(settings); }); builder.AddSingleton <IFundingService, FundingService>(); builder.AddSingleton <IValidator <PolicyCreateModel>, PolicyCreateModelValidator>(); builder.AddSingleton <IValidator <SpecificationCreateModel>, SpecificationCreateModelValidator>(); builder.AddSingleton <IValidator <CalculationCreateModel>, CalculationCreateModelValidator>(); builder.AddSingleton <IValidator <AssignDefinitionRelationshipMessage>, AssignDefinitionRelationshipMessageValidator>(); builder.AddSingleton <IValidator <SpecificationEditModel>, SpecificationEditModelValidator>(); builder.AddSingleton <IValidator <PolicyEditModel>, PolicyEditModelValidator>(); builder.AddSingleton <IValidator <CalculationEditModel>, CalculationEditModelValidator>(); builder.AddSingleton <IResultsRepository, ResultsRepository>(); builder.AddResultsInterServiceClient(Configuration); builder.AddUserProviderFromRequest(); builder.AddSearch(Configuration); builder.AddServiceBus(Configuration); builder.AddCaching(Configuration); builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.External"); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.External"); builder.AddLogging("CalculateFunding.Api.External"); builder.AddTelemetry(); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); builder.AddHttpContextAccessor(); builder.AddJobsInterServiceClient(Configuration); builder.AddSingleton <IResultsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new ResiliencePolicies() { CalculationProviderResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), SpecificationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), AllocationNotificationFeedSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ProviderProfilingRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), PublishedProviderCalculationResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), PublishedProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CalculationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ProviderCalculationResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy), ProviderChangesRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CsvBlobPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); builder.AddHealthCheckMiddleware(); builder.AddTransient <ContentTypeCheckMiddleware>(); ServiceProvider = 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"); } }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { // These registrations of the functions themselves are just for the DebugQueue. Ideally we don't want these registered in production if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") { builder.AddScoped <OnProviderResultsSpecificationCleanup>(); builder.AddScoped <OnReIndexCalculationResults>(); builder.AddScoped <OnCalculationResultsCsvGeneration>(); builder.AddScoped <OnCalculationResultsCsvGenerationTimer>(); builder.AddScoped <OnMergeSpecificationInformationForProviderWithResults>(); builder.AddScoped <OnMergeSpecificationInformationForProviderWithResultsFailure>(); builder.AddScoped <OnDeleteCalculationResults>(); builder.AddScoped <OnDeleteCalculationResultsFailure>(); builder.AddScoped <OnSearchIndexWriterEventTrigger>(); builder.AddScoped <OnSearchIndexWriterEventTriggerFailure>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <ISpecificationsWithProviderResultsService, SpecificationsWithProviderResultsService>(); builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>(); builder.AddSingleton <IConfiguration>(config); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>(); builder.AddSingleton <IResultsService, ResultsService>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder.AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder.AddSingleton <IDeadletterService, DeadletterService>(); builder.AddSingleton <IProviderCalculationResultsReIndexerService, ProviderCalculationResultsReIndexerService>(); builder.AddTransient <ICsvUtils, CsvUtils>(); builder .AddTransient <IProviderResultsCsvGeneratorService, ProviderResultsCsvGeneratorService>() .AddTransient <IHealthChecker, ProviderResultsCsvGeneratorService>(); builder.AddTransient <IProviderResultsToCsvRowsTransformation, ProviderResultsToCsvRowsTransformation>(); builder.AddSingleton <IFileSystemAccess, FileSystemAccess>(); builder.AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>(); builder .AddSingleton <ISearchIndexWriterSettings, SearchIndexWriterSettings>((ctx) => { IConfigurationSection setttingConfig = config.GetSection("searchIndexWriterSettings"); return(new SearchIndexWriterSettings(setttingConfig)); }); builder.AddSingleton <CommonStorage.IBlobClient>(ctx => { CommonStorage.BlobStorageOptions options = new CommonStorage.BlobStorageOptions(); config.Bind("AzureStorageSettings", options); options.ContainerName = "calcresults"; CommonStorage.IBlobContainerRepository blobContainerRepository = new CommonStorage.BlobContainerRepository(options); return(new CommonStorage.BlobClient(blobContainerRepository)); }); builder.AddScoped <ISearchIndexProcessorFactory, SearchIndexProcessorFactory>(); builder.AddScoped <ISearchIndexDataReader <ProviderResultDataKey, ProviderResult>, ProviderCalculationResultsIndexDataReader>(); builder.AddScoped <ISearchIndexTrasformer <ProviderResult, ProviderCalculationResultsIndex>, ProviderCalculationResultsIndexTransformer>(); builder.AddScoped <ISearchIndexProcessor, ProviderCalculationResultsIndexProcessor>(); builder.AddScoped <ISearchIndexWriterService, SearchIndexWriterService>(); builder.AddCaching(config); builder.AddSingleton <ICalculationResultsRepository, CalculationResultsRepository>((ctx) => { CosmosDbSettings calssDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", calssDbSettings); calssDbSettings.ContainerName = "calculationresults"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(calssDbSettings); EngineSettings engineSettings = ctx.GetService <EngineSettings>(); return(new CalculationResultsRepository(calcsCosmosRepostory, engineSettings)); }); builder.AddSingleton <IProviderSourceDatasetRepository, ProviderSourceDatasetRepository>((ctx) => { CosmosDbSettings provDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", provDbSettings); provDbSettings.ContainerName = "providerdatasets"; CosmosRepository calcsCosmosRepostory = new CosmosRepository(provDbSettings); return(new ProviderSourceDatasetRepository(calcsCosmosRepostory)); }); builder .AddSingleton <IBlobClient, AzureStorage.BlobClient>((ctx) => { AzureStorageSettings storageSettings = new AzureStorageSettings(); config.Bind("AzureStorageSettings", storageSettings); storageSettings.ContainerName = "calcresults"; return(new AzureStorage.BlobClient(storageSettings)); }); builder.AddSearch(config); builder .AddSingleton <ISearchRepository <ProviderCalculationResultsIndex>, SearchRepository <ProviderCalculationResultsIndex> >(); builder.AddServiceBus(config, "results"); builder.AddCaching(config); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Results"); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Results"); builder.AddLogging("CalculateFunding.Functions.Results"); builder.AddTelemetry(); builder.AddEngineSettings(config); builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddProvidersInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan); MapperConfiguration resultsConfig = new MapperConfiguration(c => { c.AddProfile <ResultsMappingProfile>(); }); builder.AddSingleton(resultsConfig.CreateMapper()); builder.AddFeatureToggling(config); builder.AddSingleton <ICancellationTokenProvider, InactiveCancellationTokenProvider>(); PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config); ResiliencePolicies resultsResiliencePolicies = CreateResiliencePolicies(policySettings); builder.AddSingleton <IResultsResiliencePolicies>(resultsResiliencePolicies); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }
private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config) { builder .AddSingleton <OnTestSpecificationProviderResultsCleanup>(); builder .AddSingleton <OnEditSpecificationEvent>(); builder .AddSingleton <OnTestExecution>(); builder .AddSingleton <IBuildProjectRepository, BuildProjectRepository>(); builder .AddSingleton <IGherkinParserService, GherkinParserService>(); builder .AddSingleton <IGherkinParser, GherkinParser>(); builder .AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>(); builder .AddSingleton <IStepParserFactory, StepParserFactory>(); builder .AddSingleton <ITestResultsRepository, TestResultsRepository>(); builder .AddSingleton <ISpecificationRepository, SpecificationRepository>(); builder .AddSingleton <IScenariosRepository, ScenariosRepository>(); builder .AddSingleton <ITestEngineService, Services.TestRunner.Services.TestEngineService>(); builder .AddSingleton <ITestEngine, Services.TestRunner.TestEngine>(); builder .AddSingleton <IGherkinExecutor, GherkinExecutor>(); builder .AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder.AddSingleton <IProviderService, ProviderService>(); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>((ctx) => { CosmosDbSettings providersDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", providersDbSettings); providersDbSettings.CollectionName = "providerdatasets"; CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings); EngineSettings engineSettings = ctx.GetService <EngineSettings>(); return(new ProviderSourceDatasetsRepository(providersCosmosRepostory, engineSettings)); }); builder.AddSingleton <IProviderResultsRepository, ProviderResultsRepository>((ctx) => { CosmosDbSettings providersDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", providersDbSettings); providersDbSettings.CollectionName = "calculationresults"; CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings); ICacheProvider cacheProvider = ctx.GetService <ICacheProvider>(); return(new ProviderResultsRepository(providersCosmosRepostory)); }); builder.AddSingleton <ITestResultsSearchService, TestResultsSearchService>(); builder.AddSingleton <ITestResultsCountsService, TestResultsCountsService>(); MapperConfiguration resultsMappingConfiguration = new MapperConfiguration(c => { c.AddProfile <ResultsMappingProfile>(); c.AddProfile <ProviderMappingProfile>(); }); builder .AddSingleton(resultsMappingConfiguration.CreateMapper()); builder.AddSingleton <ITestResultsService, TestResultsService>(); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development") { builder.AddCosmosDb(config, "testresults"); } else { builder.AddCosmosDb(config); } builder.AddSearch(config); builder.AddSpecificationsInterServiceClient(config); builder.AddScenariosInterServiceClient(config); builder.AddCalcsInterServiceClient(config); builder.AddResultsInterServiceClient(config); builder.AddCaching(config); builder.AddApplicationInsights(config, "CalculateFunding.Functions.TestEngine"); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.TestEngine", TelemetryChannelType.Sync); builder.AddLogging("CalculateFunding.Functions.TestEngine"); builder.AddTelemetry(); builder.AddEngineSettings(config); builder.AddPolicySettings(config); builder.AddFeatureToggling(config); builder.AddSingleton <ITestRunnerResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); Policy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); ResiliencePolicies resiliencePolicies = new ResiliencePolicies() { BuildProjectRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), CacheProviderRepository = redisPolicy, ProviderResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ProviderSourceDatasetsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), ScenariosRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(new[] { totalNetworkRequestsPolicy, redisPolicy }), SpecificationRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), TestResultsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), TestResultsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy) }; return(resiliencePolicies); }); return(builder.BuildServiceProvider()); }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>(); builder.AddSingleton <IScenariosRepository, ScenariosRepository>((ctx) => { CosmosDbSettings scenariosVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", scenariosVersioningDbSettings); scenariosVersioningDbSettings.ContainerName = "tests"; CosmosRepository resultsRepostory = new CosmosRepository(scenariosVersioningDbSettings); return(new ScenariosRepository(resultsRepostory)); }); builder .AddSingleton <IScenariosService, ScenariosService>() .AddSingleton <IHealthChecker, ScenariosService>(); builder .AddSingleton <IScenariosSearchService, ScenariosSearchService>() .AddSingleton <IHealthChecker, ScenariosSearchService>(); builder.AddSingleton <IJobManagement, JobManagement>(); builder .AddSingleton <IValidator <CreateNewTestScenarioVersion>, CreateNewTestScenarioVersionValidator>(); builder .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); builder.AddSingleton <IVersionRepository <TestScenarioVersion>, VersionRepository <TestScenarioVersion> >((ctx) => { CosmosDbSettings scenariosVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", scenariosVersioningDbSettings); scenariosVersioningDbSettings.ContainerName = "tests"; CosmosRepository resultsRepostory = new CosmosRepository(scenariosVersioningDbSettings); return(new VersionRepository <TestScenarioVersion>(resultsRepostory, new NewVersionBuilderFactory <TestScenarioVersion>())); }); builder .AddSingleton <ICalcsRepository, CalcsRepository>(); builder .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>(); builder .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>(); MapperConfiguration scenariosConfig = new MapperConfiguration(c => { c.AddProfile <DatasetsMappingProfile>(); }); builder .AddSingleton(scenariosConfig.CreateMapper()); builder.AddCalculationsInterServiceClient(Configuration); builder.AddSpecificationsInterServiceClient(Configuration); builder.AddDatasetsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddSearch(Configuration); builder .AddSingleton <ISearchRepository <ScenarioIndex>, SearchRepository <ScenarioIndex> >(); builder .AddSingleton <ISearchRepository <TestScenarioResultIndex>, SearchRepository <TestScenarioResultIndex> >(); builder.AddServiceBus(Configuration); builder.AddCaching(Configuration); builder.AddFeatureToggling(Configuration); builder.AddApplicationInsightsTelemetry(); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Scenarios"); builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Scenarios"); builder.AddLogging("CalculateFunding.Api.Scenarios"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); builder.AddPolicySettings(Configuration); builder.AddSingleton <IScenariosResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); AsyncPolicy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new ScenariosResiliencePolicies() { CalcsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ScenariosRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), SpecificationsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), ScenariosApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); return(new JobManagementResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy), }); }); if (Configuration.IsSwaggerEnabled()) { builder.ConfigureSwaggerServices(title: "Scenarios Microservice API"); } }
public void RegisterComponents(IServiceCollection builder) { builder.AddSingleton <ISpecificationsRepository, SpecificationsRepository>(); builder .AddSingleton <ISpecificationsService, SpecificationsService>() .AddSingleton <IHealthChecker, SpecificationsService>(); builder.AddSingleton <IValidator <PolicyCreateModel>, PolicyCreateModelValidator>(); builder.AddSingleton <IValidator <PolicyEditModel>, PolicyEditModelValidator>(); builder.AddSingleton <IValidator <CalculationCreateModel>, CalculationCreateModelValidator>(); builder.AddSingleton <IValidator <SpecificationCreateModel>, SpecificationCreateModelValidator>(); builder.AddSingleton <IValidator <CalculationEditModel>, CalculationEditModelValidator>(); builder.AddSingleton <IValidator <SpecificationEditModel>, SpecificationEditModelValidator>(); builder.AddSingleton <IValidator <AssignDefinitionRelationshipMessage>, AssignDefinitionRelationshipMessageValidator>(); builder .AddSingleton <ISpecificationsSearchService, SpecificationsSearchService>() .AddSingleton <IHealthChecker, SpecificationsSearchService>(); builder.AddSingleton <IResultsRepository, ResultsRepository>(); builder.AddSingleton <ICalculationsRepository, CalculationsRepository>(); builder.AddSingleton <IFundingService, FundingService>(); builder.AddSingleton <ICosmosRepository, CosmosRepository>(); builder.AddSingleton <IVersionRepository <SpecificationVersion>, VersionRepository <SpecificationVersion> >((ctx) => { CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings(); Configuration.Bind("CosmosDbSettings", specsVersioningDbSettings); specsVersioningDbSettings.CollectionName = "specs"; CosmosRepository resultsRepostory = new CosmosRepository(specsVersioningDbSettings); return(new VersionRepository <SpecificationVersion>(resultsRepostory)); }); MapperConfiguration mappingConfig = new MapperConfiguration(c => c.AddProfile <SpecificationsMappingProfile>()); builder.AddFeatureToggling(Configuration); builder.AddSingleton(mappingConfig.CreateMapper()); builder.AddUserProviderFromRequest(); builder.AddCosmosDb(Configuration); builder.AddServiceBus(Configuration); builder.AddSearch(Configuration); builder.AddCaching(Configuration); builder.AddResultsInterServiceClient(Configuration); builder.AddJobsInterServiceClient(Configuration); builder.AddCalcsInterServiceClient(Configuration); builder.AddPolicySettings(Configuration); builder.AddSingleton <ISpecificationsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); Polly.Policy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy); return(new SpecificationsResiliencePolicies() { JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy) }); }); builder.AddApplicationInsights(Configuration, "CalculateFunding.Api.Specs"); builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Apis.Specs"); builder.AddLogging("CalculateFunding.Apis.Specs"); builder.AddTelemetry(); builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration); builder.AddHttpContextAccessor(); builder.AddHealthCheckMiddleware(); }
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"); } }