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);
        }
Beispiel #2
0
        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 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);
        }
Beispiel #4
0
 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)
     });
 }
Beispiel #5
0
        private static CalculatorResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings)
        {
            BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

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

            return(resiliencePolicies);
        }
        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)
            });
        }
Beispiel #7
0
        private static ResiliencePolicies CreateResiliencePolicies(PolicySettings policySettings)
        {
            BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

            return(new ResiliencePolicies
            {
                CalculationsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                CalculationsSearchRepository = SearchResiliencePolicyHelper.GenerateSearchPolicy(totalNetworkRequestsPolicy),
                CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy),
                CalculationsVersionsRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                SpecificationsRepositoryPolicy = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                BuildProjectRepositoryPolicy = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                MessagePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy),
                JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                SourceFilesRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                DatasetsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy)
            });
        }
Beispiel #8
0
        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),
     });
 }
        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");
            }
        }
Beispiel #11
0
        public void RegisterComponents(IServiceCollection builder)
        {
            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            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, TestEngineService>()
            .AddSingleton <IHealthChecker, 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();

                Configuration.Bind("CosmosDbSettings", providersDbSettings);

                providersDbSettings.CollectionName = "providersources";

                CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings);

                EngineSettings engineSettings = ctx.GetService <EngineSettings>();

                return(new ProviderSourceDatasetsRepository(providersCosmosRepostory, engineSettings));
            });

            builder.AddSingleton <IProviderResultsRepository, ProviderResultsRepository>((ctx) =>
            {
                CosmosDbSettings providersDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", providersDbSettings);

                providersDbSettings.CollectionName = "calculationresults";

                CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings);

                ICacheProvider cacheProvider = ctx.GetService <ICacheProvider>();

                return(new ProviderResultsRepository(providersCosmosRepostory));
            });

            builder
            .AddSingleton <ITestResultsSearchService, TestResultsSearchService>()
            .AddSingleton <IHealthChecker, TestResultsSearchService>();

            builder
            .AddSingleton <ITestResultsCountsService, TestResultsCountsService>()
            .AddSingleton <IHealthChecker, TestResultsCountsService>();

            MapperConfiguration mapperConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <ResultsMappingProfile>();
                c.AddProfile <ProviderMappingProfile>();
            });

            builder
            .AddSingleton(mapperConfig.CreateMapper());

            builder
            .AddSingleton <ITestResultsService, TestResultsService>()
            .AddSingleton <IHealthChecker, TestResultsService>();

            builder.AddSingleton <IProviderService, ProviderService>();

            builder.AddUserProviderFromRequest();

            builder.AddCosmosDb(Configuration);

            builder.AddSearch(Configuration);

            builder.AddCalcsInterServiceClient(Configuration);
            builder.AddSpecificationsInterServiceClient(Configuration);
            builder.AddScenariosInterServiceClient(Configuration);
            builder.AddResultsInterServiceClient(Configuration);

            builder.AddCaching(Configuration);

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

            builder.AddEngineSettings(Configuration);

            builder.AddPolicySettings(Configuration);

            builder.AddHttpContextAccessor();

            builder.AddFeatureToggling(Configuration);

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

                BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                Policy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy);

                return(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)
                });
            });

            builder.AddHealthCheckMiddleware();
        }
Beispiel #12
0
        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)
                });
            });
        }
Beispiel #13
0
        public void RegisterComponents(IServiceCollection builder)
        {
            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();

            builder
            .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>();

            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            builder
            .AddSingleton <IGherkinParserService, GherkinParserService>();

            builder
            .AddSingleton <IGherkinParser, GherkinParser>();

            builder
            .AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>();

            builder
            .AddSingleton <IStepParserFactory, StepParserFactory>();

            builder.AddSingleton <ITestResultsRepository, TestResultsRepository>((ctx) =>
            {
                CosmosDbSettings providersDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", providersDbSettings);

                providersDbSettings.ContainerName = "testresults";

                CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings);

                ILogger logger = ctx.GetService <ILogger>();

                EngineSettings engineSettings = ctx.GetService <EngineSettings>();

                return(new TestResultsRepository(providersCosmosRepostory, logger, engineSettings));
            });

            builder
            .AddSingleton <IScenariosRepository, ScenariosRepository>();

            builder
            .AddScoped <ITestEngineService, TestEngineService>()
            .AddScoped <IHealthChecker, TestEngineService>();

            builder
            .AddSingleton <ITestEngine, Services.TestRunner.TestEngine>();

            builder
            .AddSingleton <IGherkinExecutor, GherkinExecutor>();

            builder
            .AddSingleton <ICalculationsRepository, CalculationsRepository>();

            builder.AddSingleton <IProviderSourceDatasetsRepository, ProviderSourceDatasetsRepository>((ctx) =>
            {
                CosmosDbSettings providersDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", providersDbSettings);

                providersDbSettings.ContainerName = "providersources";

                CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings);

                EngineSettings engineSettings = ctx.GetService <EngineSettings>();

                return(new ProviderSourceDatasetsRepository(providersCosmosRepostory, engineSettings));
            });

            builder.AddSingleton <IProviderResultsRepository, ProviderResultsRepository>((ctx) =>
            {
                CosmosDbSettings providersDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", providersDbSettings);

                providersDbSettings.ContainerName = "calculationresults";

                CosmosRepository providersCosmosRepostory = new CosmosRepository(providersDbSettings);

                ICacheProvider cacheProvider = ctx.GetService <ICacheProvider>();

                return(new ProviderResultsRepository(providersCosmosRepostory));
            });

            builder
            .AddSingleton <ITestResultsSearchService, TestResultsSearchService>()
            .AddSingleton <IHealthChecker, TestResultsSearchService>();

            builder
            .AddSingleton <ITestResultsCountsService, TestResultsCountsService>()
            .AddSingleton <IHealthChecker, TestResultsCountsService>();

            MapperConfiguration mapperConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <TestEngineMappingProfile>();
            });


            builder.AddScoped <IJobManagement, JobManagement>();

            builder
            .AddSingleton(mapperConfig.CreateMapper());

            builder
            .AddScoped <ITestResultsService, TestResultsService>()
            .AddScoped <IHealthChecker, TestResultsService>();

            builder.AddSearch(Configuration);
            builder
            .AddSingleton <ISearchRepository <TestScenarioResultIndex>, SearchRepository <TestScenarioResultIndex> >();

            builder.AddServiceBus(Configuration);

            builder.AddCalculationsInterServiceClient(Configuration);
            builder.AddSpecificationsInterServiceClient(Configuration);
            builder.AddScenariosInterServiceClient(Configuration);
            builder.AddProvidersInterServiceClient(Configuration);
            builder.AddJobsInterServiceClient(Configuration);

            builder.AddCaching(Configuration);

            builder.AddApplicationInsightsTelemetry();
            builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.TestEngine");
            builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.TestEngine");
            builder.AddLogging("CalculateFunding.Api.TestEngine");
            builder.AddTelemetry();

            builder.AddEngineSettings(Configuration);

            builder.AddPolicySettings(Configuration);

            builder.AddHttpContextAccessor();

            builder.AddFeatureToggling(Configuration);

            builder.AddSingleton((System.Func <System.IServiceProvider, ITestRunnerResiliencePolicies>)((ctx) =>
            {
                PolicySettings policySettings = ctx.GetService <PolicySettings>();

                AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                AsyncPolicy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy);

                return(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)
                });
            }));

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

                AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                return(new JobManagementResiliencePolicies()
                {
                    JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                });
            });

            builder.AddHealthCheckMiddleware();

            if (Configuration.IsSwaggerEnabled())
            {
                builder.ConfigureSwaggerServices(title: "TestRunner Microservice API");
            }
        }
Beispiel #14
0
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();
            builder.AddSingleton <ISpecificationTemplateVersionChangedHandler, SpecificationTemplateVersionChangedHandler>();

            builder.AddSingleton <IQueueCreateSpecificationJobActions, QueueCreateSpecificationJobAction>();
            builder.AddSingleton <IQueueEditSpecificationJobActions, QueueEditSpecificationJobActions>();
            builder.AddSingleton <IQueueDeleteSpecificationJobActions, QueueDeleteSpecificationJobAction>();

            // These registrations of the functions themselves are just for the DebugQueue. Ideally we don't want these registered in production
            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                builder.AddScoped <OnAddRelationshipEvent>();
                builder.AddScoped <OnReIndexSpecification>();
                builder.AddScoped <OnDeleteSpecifications>();
                builder.AddScoped <OnDeleteSpecificationsFailure>();
            }

            builder.AddSingleton <ISpecificationsRepository, SpecificationsRepository>((ctx) =>
            {
                CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", specsVersioningDbSettings);

                specsVersioningDbSettings.ContainerName = "specs";

                CosmosRepository resultsRepository = new CosmosRepository(specsVersioningDbSettings);

                return(new SpecificationsRepository(resultsRepository));
            });

            builder.AddSingleton <ISpecificationsService, SpecificationsService>();
            builder.AddSingleton <IValidator <SpecificationCreateModel>, SpecificationCreateModelValidator>();
            builder.AddSingleton <IValidator <SpecificationEditModel>, SpecificationEditModelValidator>();
            builder.AddSingleton <IValidator <AssignDefinitionRelationshipMessage>, AssignDefinitionRelationshipMessageValidator>();
            builder.AddSingleton <IValidator <AssignSpecificationProviderVersionModel>, AssignSpecificationProviderVersionModelValidator>();
            builder.AddSingleton <ISpecificationsSearchService, SpecificationsSearchService>();
            builder.AddSingleton <IResultsRepository, ResultsRepository>();
            builder.AddSingleton <ISpecificationIndexer, SpecificationIndexer>();
            builder.AddSingleton <IProducerConsumerFactory, ProducerConsumerFactory>();
            builder.AddSingleton <ISpecificationIndexingService, SpecificationIndexingService>();
            builder.AddSingleton <IDeadletterService, DeadletterService>();

            builder.AddSingleton <ITemplateMetadataResolver>((ctx) =>
            {
                TemplateMetadataResolver resolver = new TemplateMetadataResolver();

                TemplateMetadataGenerator schema10Generator = new TemplateMetadataGenerator(ctx.GetService <ILogger>());

                resolver.Register("1.0", schema10Generator);

                return(resolver);
            });

            builder
            .AddSingleton <IBlobClient, BlobClient>((ctx) =>
            {
                AzureStorageSettings storageSettings = new AzureStorageSettings();

                config.Bind("AzureStorageSettings", storageSettings);

                storageSettings.ContainerName = "providerversions";

                return(new BlobClient(storageSettings));
            });

            builder.AddSingleton <IVersionRepository <Models.Specs.SpecificationVersion>, VersionRepository <Models.Specs.SpecificationVersion> >((ctx) =>
            {
                CosmosDbSettings specsVersioningDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", specsVersioningDbSettings);

                specsVersioningDbSettings.ContainerName = "specs";

                CosmosRepository cosmosRepository = new CosmosRepository(specsVersioningDbSettings);

                return(new VersionRepository <Models.Specs.SpecificationVersion>(cosmosRepository, new NewVersionBuilderFactory <SpecificationVersion>()));
            });

            builder
            .AddSingleton <IJobManagement, JobManagement>();

            PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config);

            AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

            builder.AddSingleton <ISpecificationsResiliencePolicies>((ctx) =>
            {
                Polly.AsyncPolicy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy);

                return(new SpecificationsResiliencePolicies()
                {
                    PoliciesApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    CalcsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    ProvidersApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    DatasetsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    SpecificationsSearchRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    SpecificationsRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    ResultsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    CacheProvider = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy)
                });
            });

            builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) => new JobManagementResiliencePolicies()
            {
                JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy)
            });

            MapperConfiguration mappingConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <SpecificationsMappingProfile>();
            });

            builder.AddSingleton(mappingConfig.CreateMapper());

            builder.AddServiceBus(config, "specs");

            builder.AddSearch(config);
            builder
            .AddSingleton <ISearchRepository <SpecificationIndex>, SearchRepository <SpecificationIndex> >();

            builder.AddCaching(config);


            builder.AddResultsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddProvidersInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddCalculationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddDatasetsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);

            builder.AddPolicySettings(config);

            builder.AddFeatureToggling(config);

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

            builder.AddScoped <IUserProfileProvider, UserProfileProvider>();

            return(builder.BuildServiceProvider());
        }
Beispiel #15
0
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            builder
            .AddSingleton <OnDataDefinitionChanges>();

            builder
            .AddSingleton <OnDatasetEvent>();

            builder
            .AddSingleton <OnDatasetValidationEvent>();

            builder
            .AddSingleton <IDefinitionsService, DefinitionsService>();

            builder
            .AddSingleton <IDatasetService, DatasetService>();

            builder
            .AddSingleton <IProcessDatasetService, ProcessDatasetService>();

            builder
            .AddSingleton <IValidator <CreateNewDatasetModel>, CreateNewDatasetModelValidator>();

            builder
            .AddSingleton <IValidator <DatasetVersionUpdateModel>, DatasetVersionUpdateModelValidator>();

            builder
            .AddSingleton <IValidator <DatasetMetadataModel>, DatasetMetadataModelValidator>();

            builder
            .AddSingleton <IValidator <GetDatasetBlobModel>, GetDatasetBlobModelValidator>();

            builder
            .AddSingleton <IValidator <CreateDefinitionSpecificationRelationshipModel>, CreateDefinitionSpecificationRelationshipModelValidator>();

            builder
            .AddSingleton <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();

                config.Bind("AzureStorageSettings", storageSettings);

                storageSettings.ContainerName = "datasets";

                return(new BlobClient(storageSettings));
            });

            builder.AddSingleton <IProvidersResultsRepository, ProvidersResultsRepository>((ctx) =>
            {
                CosmosDbSettings dbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", dbSettings);

                dbSettings.CollectionName = "providerdatasets";

                CosmosRepository calcsCosmosRepostory = new CosmosRepository(dbSettings);

                return(new ProvidersResultsRepository(calcsCosmosRepostory));
            });

            builder.AddSingleton <IDatasetRepository, DataSetsRepository>();

            builder.AddSingleton <IDatasetSearchService, DatasetSearchService>();

            builder.AddSingleton <IDatasetDefinitionSearchService, DatasetDefinitionSearchService>();

            builder
            .AddSingleton <IDefinitionSpecificationRelationshipService, DefinitionSpecificationRelationshipService>();

            builder
            .AddSingleton <ISpecificationsRepository, SpecificationsRepository>();

            builder
            .AddSingleton <IExcelDatasetReader, ExcelDatasetReader>();

            builder.AddSingleton <IProviderService, ProviderService>();

            builder
            .AddSingleton <ICalcsRepository, CalcsRepository>();

            builder
            .AddSingleton <IResultsRepository, ResultsRepository>();

            builder.AddTransient <IValidator <DatasetUploadValidationModel>, DatasetItemValidator>();

            MapperConfiguration dataSetsConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <DatasetsMappingProfile>();
                c.AddProfile <ProviderMappingProfile>();
            });

            builder
            .AddSingleton(dataSetsConfig.CreateMapper());

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

                config.Bind("CosmosDbSettings", ProviderSourceDatasetVersioningDbSettings);

                ProviderSourceDatasetVersioningDbSettings.CollectionName = "providerdatasets";

                CosmosRepository cosmosRepository = new CosmosRepository(ProviderSourceDatasetVersioningDbSettings);

                return(new VersionRepository <ProviderSourceDatasetVersion>(cosmosRepository));
            });

            builder.AddSingleton <IDatasetsAggregationsRepository, DatasetsAggregationsRepository>((ctx) =>
            {
                CosmosDbSettings dbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", dbSettings);

                dbSettings.CollectionName = "datasetaggregations";

                CosmosRepository aggsCosmosRepostory = new CosmosRepository(dbSettings);

                return(new DatasetsAggregationsRepository(aggsCosmosRepostory));
            });

            builder.AddCalcsInterServiceClient(config);
            builder.AddResultsInterServiceClient(config);
            builder.AddSpecificationsInterServiceClient(config);
            builder.AddJobsInterServiceClient(config);

            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                builder.AddCosmosDb(config, "datasets");
            }
            else
            {
                builder.AddCosmosDb(config);
            }

            builder.AddSearch(config);

            builder.AddServiceBus(config);

            builder.AddCaching(config);

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

            builder.AddPolicySettings(config);

            builder.AddFeatureToggling(config);

            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)
                });
            });

            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 <OnScaleUpCosmosDbCollection>();
                builder.AddScoped <OnScaleDownCosmosDbCollection>();
                builder.AddScoped <OnIncrementalScaleDownCosmosDbCollection>();
            }

            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();

            builder.AddSingleton <ICosmosDbScalingRepositoryProvider, CosmosDbScalingRepositoryProvider>();

            builder.AddSingleton <ICosmosDbScalingService, CosmosDbScalingService>();

            builder.AddSingleton <ICosmosDbScalingRequestModelBuilder, CosmosDbScalingRequestModelBuilder>();

            builder.AddSingleton <ICosmosDbThrottledEventsFilter, CosmosDbThrottledEventsFilter>();
            builder.AddSingleton <IValidator <ScalingConfigurationUpdateModel>, ScalingConfigurationUpdateModelValidator>();
            builder.AddSingleton <IJobManagement, JobManagement>();

            builder.AddSingleton <CalculationProviderResultsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "calculationresults";

                CosmosRepository cosmosRepostory = new CosmosRepository(cosmosDbSettings);

                return(new CalculationProviderResultsScalingRepository(cosmosRepostory));
            });

            builder.AddSingleton <ProviderSourceDatasetsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "providerdatasets";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new ProviderSourceDatasetsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <PublishedFundingScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "publishedfunding";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new PublishedFundingScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <CalculationsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "calcs";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new CalculationsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <JobsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "jobs";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new JobsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <DatasetAggregationsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "datasetaggregations";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new DatasetAggregationsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <DatasetsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "datasets";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new DatasetsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <ProfilingScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "profiling";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new ProfilingScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <SpecificationsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "specs";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new SpecificationsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <TestResultsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "testresults";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new TestResultsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <TestsScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "tests";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new TestsScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <UsersScalingRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "users";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new UsersScalingRepository(cosmosRepository));
            });

            builder.AddSingleton <ICosmosDbScalingConfigRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.ContainerName = "cosmosscalingconfig";

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new CosmosDbScalingConfigRepository(cosmosRepository));
            });

            builder.AddCaching(config);

            builder.AddScoped <IUserProfileProvider, UserProfileProvider>();

            builder.AddJobsInterServiceClient(config);

            builder.AddServiceBus(config, "cosmosdbscaling");

            builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.CosmosDbScaling");

            builder.AddLogging("CalculateFunding.Functions.CosmosDbScaling", config);

            builder.AddTelemetry();

            builder.AddSingleton <ICosmosDbScalingResiliencePolicies>(m =>
            {
                PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config);

                AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                CosmosDbScalingResiliencePolicies resiliencePolicies = new CosmosDbScalingResiliencePolicies()
                {
                    ScalingRepository       = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    ScalingConfigRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy),
                    JobsApiClient           = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    CacheProvider           = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy)
                };

                return(resiliencePolicies);
            });

            builder.AddSingleton <IJobManagementResiliencePolicies>((ctx) =>
            {
                PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(config);

                AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                return(new JobManagementResiliencePolicies()
                {
                    JobsApiClient = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                });
            });

            return(builder.BuildServiceProvider());
        }
        public void RegisterComponents(IServiceCollection builder)
        {
            builder
            .AddSpecificationsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan)
            .AddCalculationsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan)
            .AddResultsInterServiceClient(Configuration, handlerLifetime: Timeout.InfiniteTimeSpan);

            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();

            builder.AddSingleton <IIoCValidatorFactory, ValidatorFactory>()
            .AddSingleton <IValidator <Reference>, AuthorValidator>();
            builder
            .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>();

            builder
            .AddSingleton <IFundingStreamService, FundingStreamService>()
            .AddSingleton <IHealthChecker, FundingStreamService>()
            .AddSingleton <IValidator <FundingStreamSaveModel>, FundingStreamSaveModelValidator>();

            builder
            .AddSingleton <IFundingPeriodService, FundingPeriodService>()
            .AddSingleton <IHealthChecker, FundingPeriodService>()
            .AddSingleton <IFundingPeriodValidator, FundingPeriodValidator>();

            builder
            .AddSingleton <IFundingSchemaService, FundingSchemaService>()
            .AddSingleton <IHealthChecker, FundingSchemaService>();

            builder
            .AddSingleton <IFundingConfigurationService, FundingConfigurationService>()
            .AddSingleton <IHealthChecker, FundingConfigurationService>();

            builder
            .AddSingleton <IFundingTemplateService, FundingTemplateService>()
            .AddSingleton <IHealthChecker, FundingTemplateService>();

            builder
            .AddSingleton <IFundingTemplateValidationService, FundingTemplateValidationService>()
            .AddSingleton <IHealthChecker, FundingTemplateValidationService>();

            builder
            .AddSingleton <IFundingDateService, FundingDateService>()
            .AddSingleton <IHealthChecker, FundingDateService>();

            builder
            .AddSingleton <IFundingSchemaRepository, FundingSchemaRepository>((ctx) =>
            {
                BlobStorageOptions blobStorageOptions = new BlobStorageOptions();

                Configuration.Bind("AzureStorageSettings", blobStorageOptions);

                blobStorageOptions.ContainerName = "fundingschemas";

                IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(blobStorageOptions);
                return(new FundingSchemaRepository(blobContainerRepository));
            });

            builder
            .AddSingleton <IFundingTemplateRepository, FundingTemplateRepository>((ctx) =>
            {
                BlobStorageOptions blobStorageOptions = new BlobStorageOptions();

                Configuration.Bind("AzureStorageSettings", blobStorageOptions);

                blobStorageOptions.ContainerName = "fundingtemplates";

                IBlobContainerRepository blobContainerRepository = new BlobContainerRepository(blobStorageOptions);
                return(new FundingTemplateRepository(blobContainerRepository));
            });

            builder
            .AddSingleton <IPolicyRepository, PolicyRepository>((ctx) =>
            {
                CosmosDbSettings cosmosDbSettings = new CosmosDbSettings
                {
                    ContainerName = "policy"
                };

                Configuration.Bind("CosmosDbSettings", cosmosDbSettings);

                CosmosRepository cosmosRepository = new CosmosRepository(cosmosDbSettings);

                return(new PolicyRepository(cosmosRepository));
            });

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

                AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

                Polly.AsyncPolicy redisPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy);

                return(new PolicyResiliencePolicies
                {
                    PolicyRepository = ResiliencePolicyHelpers.GenerateRestRepositoryPolicy(totalNetworkRequestsPolicy),
                    CacheProvider = redisPolicy,
                    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)
                });
            });

            builder.AddSingleton <IValidator <FundingConfiguration>, SaveFundingConfigurationValidator>();
            builder.AddSingleton <IValidator <FundingPeriodsJsonModel>, FundingPeriodJsonModelValidator>();
            builder.AddSingleton <IValidator <FundingDate>, SaveFundingDateValidator>();

            RegisterTemplateBuilderComponents(builder);

            builder.AddPolicySettings(Configuration);
            builder.AddJobsInterServiceClient(Configuration);

            MapperConfiguration fundingConfMappingConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <FundingConfigurationMappingProfile>();
            });

            builder
            .AddSingleton(fundingConfMappingConfig.CreateMapper());

            builder.AddSearch(Configuration);

            builder.AddSingleton <TemplateSearchService>()
            .AddSingleton <IHealthChecker, TemplateSearchService>();

            builder
            .AddSingleton <ISearchRepository <TemplateIndex>, SearchRepository <TemplateIndex> >();

            builder.AddCaching(Configuration);

            builder.AddApplicationInsightsTelemetry();
            builder.AddApplicationInsightsTelemetryClient(Configuration, "CalculateFunding.Api.Policy");
            builder.AddApplicationInsightsServiceName(Configuration, "CalculateFunding.Api.Policy");
            builder.AddLogging("CalculateFunding.Api.Policy");
            builder.AddTelemetry();

            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            builder.AddHttpContextAccessor();
            builder.AddHealthCheckMiddleware();

            if (Configuration.IsSwaggerEnabled())
            {
                builder.ConfigureSwaggerServices(title: "Policy Microservice API");
            }
        }
Beispiel #18
0
        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());
        }
Beispiel #19
0
        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");
            }
        }
Beispiel #20
0
        public void RegisterComponents(IServiceCollection builder)
        {
            builder
            .AddSingleton <IJobDefinitionsService, JobDefinitionsService>()
            .AddSingleton <IHealthChecker, JobDefinitionsService>();

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

            builder
            .AddSingleton <INotificationService, NotificationService>();

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

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

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

                Configuration.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobdefinitions";

                CosmosRepository jobDefinitionsCosmosRepostory = new CosmosRepository(cosmosDbSettings);

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

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

                Configuration.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobs";

                CosmosRepository jobCosmosRepostory = new CosmosRepository(cosmosDbSettings);

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

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

            builder.AddSingleton(mappingConfig.CreateMapper());

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

            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            builder.AddPolicySettings(Configuration);

            builder.AddCaching(Configuration);

            builder.AddServiceBus(Configuration);

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

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

            builder.AddHealthCheckMiddleware();
        }
Beispiel #21
0
        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");
            }
        }
Beispiel #22
0
        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());
        }
Beispiel #23
0
        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");
            }
        }
        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)
        {
            // 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());
        }
Beispiel #26
0
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            builder
            .AddSingleton <OnJobNotification>();

            builder
            .AddSingleton <OnCheckForJobTimeout>();

            builder
            .AddSingleton <IJobManagementService, JobManagementService>();

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

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

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobs";

                CosmosRepository jobCosmosRepostory = new CosmosRepository(cosmosDbSettings);

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

            builder
            .AddSingleton <INotificationService, NotificationService>();

            builder
            .AddSingleton <IJobDefinitionsService, JobDefinitionsService>();

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

                config.Bind("CosmosDbSettings", cosmosDbSettings);

                cosmosDbSettings.CollectionName = "jobdefinitions";

                CosmosRepository jobDefinitionsCosmosRepostory = new CosmosRepository(cosmosDbSettings);

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

            builder.AddServiceBus(config);

            builder.AddPolicySettings(config);

            builder.AddCaching(config);

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

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

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

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

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

            builder.AddTelemetry();

            return(builder.BuildServiceProvider());
        }
Beispiel #27
0
        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());
        }
Beispiel #28
0
        public void RegisterComponents(IServiceCollection builder)
        {
            builder
            .AddSingleton <ICalculationsRepository, CalculationsRepository>();

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

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

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

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

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

            builder
            .AddSingleton <ICompilerFactory, CompilerFactory>();

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

            builder
            .AddSingleton <ISourceFileGeneratorProvider, SourceFileGeneratorProvider>();

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

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

            builder
            .AddSingleton <ISpecificationRepository, SpecificationRepository>();

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

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

            builder
            .AddSingleton <ICodeMetadataGeneratorService, ReflectionCodeMetadataGenerator>();

            builder
            .AddSingleton <IDatasetRepository, DatasetRepository>();

            builder.AddSingleton <ISourceCodeService, SourceCodeService>();

            builder
            .AddSingleton <IDatasetDefinitionFieldChangesProcessor, DatasetDefinitionFieldChangesProcessor>();

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

                Configuration.Bind("CommonStorageSettings", blobStorageOptions);

                blobStorageOptions.ContainerName = "source";

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

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

                Configuration.Bind("CosmosDbSettings", calcsVersioningDbSettings);

                calcsVersioningDbSettings.CollectionName = "calcs";

                CosmosRepository resultsRepostory = new CosmosRepository(calcsVersioningDbSettings);

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

            builder
            .AddSingleton <ICancellationTokenProvider, HttpContextCancellationProvider>();

            builder.AddUserProviderFromRequest();

            builder.AddCosmosDb(Configuration);

            builder.AddSearch(Configuration);

            builder.AddServiceBus(Configuration);

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

            builder.AddCaching(Configuration);

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

            builder.AddEngineSettings(Configuration);

            builder.AddFeatureToggling(Configuration);

            builder.AddPolicySettings(Configuration);

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

                BulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);

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

            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            builder.AddHttpContextAccessor();

            builder.AddHealthCheckMiddleware();
        }
Beispiel #29
0
        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();
        }
Beispiel #30
0
        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();
        }