Пример #1
0
        public void RegisterComponents(IServiceCollection builder)
        {
            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();

            builder.AddSingleton <IValidator <SetFundingStreamCurrentProviderVersionRequest>, SetFundingStreamCurrentProviderVersionRequestValidator>();
            builder.AddSingleton <IFundingStreamProviderVersionService, FundingStreamProviderVersionService>();

            builder
            .AddSingleton <IHealthChecker, ControllerResolverHealthCheck>();

            builder.AddCaching(Configuration);

            builder
            .AddSingleton <IProviderVersionService, ProviderVersionService>()
            .AddSingleton <IHealthChecker, ProviderVersionService>();

            builder
            .AddSingleton <IProviderVersionSearchService, ProviderVersionSearchService>()
            .AddSingleton <IHealthChecker, ProviderVersionSearchService>();

            builder
            .AddSingleton <IJobManagement, JobManagement>();

            builder
            .AddSingleton <IScopedProvidersService, ScopedProvidersService>()
            .AddSingleton <IHealthChecker, ScopedProvidersService>();

            builder
            .AddSingleton <IProviderVersionUpdateCheckService, ProviderVersionUpdateCheckService>();

            builder.AddSingleton <IValidator <ProviderVersionViewModel>, UploadProviderVersionValidator>();

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

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

                Configuration.Bind("AzureStorageSettings", storageSettings);

                storageSettings.ContainerName = "providerversions";

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

            builder.AddSingleton <IProviderVersionsMetadataRepository, ProviderVersionsMetadataRepository>(
                ctx =>
            {
                CosmosDbSettings specRepoDbSettings = new CosmosDbSettings();

                Configuration.Bind("CosmosDbSettings", specRepoDbSettings);

                specRepoDbSettings.ContainerName = "providerversionsmetadata";

                CosmosRepository cosmosRepository = new CosmosRepository(specRepoDbSettings);

                return(new ProviderVersionsMetadataRepository(cosmosRepository));
            });

            builder.AddPolicySettings(Configuration);

            MapperConfiguration providerVersionsConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <ProviderVersionsMappingProfile>();
            });

            builder
            .AddSingleton(providerVersionsConfig.CreateMapper());

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

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

            builder.AddServiceBus(Configuration);

            PolicySettings policySettings = ServiceCollectionExtensions.GetPolicySettings(Configuration);

            AsyncBulkheadPolicy         totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);
            ProvidersResiliencePolicies resiliencePolicies         = CreateResiliencePolicies(totalNetworkRequestsPolicy);

            builder.AddSingleton <IJobManagementResiliencePolicies>(resiliencePolicies);

            builder.AddSingleton <IProvidersResiliencePolicies>(resiliencePolicies);

            builder
            .AddSingleton <IFileSystemCache, FileSystemCache>()
            .AddSingleton <IFileSystemAccess, FileSystemAccess>()
            .AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>();

            builder
            .AddSingleton <IProviderVersionServiceSettings>(ctx =>
            {
                ProviderVersionServiceSettings settings = new ProviderVersionServiceSettings();

                Configuration.Bind("providerversionservicesettings", settings);

                return(settings);
            });

            builder
            .AddSingleton <IScopedProvidersServiceSettings>(ctx =>
            {
                ScopedProvidersServiceSettings settings = new ScopedProvidersServiceSettings();

                Configuration.Bind("scopedprovidersservicesetting", settings);

                return(settings);
            });

            builder.AddApiKeyMiddlewareSettings((IConfigurationRoot)Configuration);

            builder.AddHealthCheckMiddleware();

            builder.AddHttpContextAccessor();

            builder.AddSearch(Configuration);

            if (Configuration.IsSwaggerEnabled())
            {
                builder.ConfigureSwaggerServices(title: "Provider Microservice API");
            }
        }
        private static IServiceProvider Register(IServiceCollection builder, IConfigurationRoot config)
        {
            // These registrations of the functions themselves are just for the DebugQueue. Ideally we don't want these registered in production
            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                builder.AddScoped <OnPopulateScopedProvidersEventTrigger>();
                builder.AddScoped <OnPopulateScopedProvidersEventTriggerFailure>();
                builder.AddScoped <OnProviderSnapshotDataLoadEventTrigger>();
                builder.AddScoped <OnProviderSnapshotDataLoadEventTriggerFailure>();
                builder.AddScoped <OnNewProviderVersionCheck>();
            }

            builder.AddSingleton <IUserProfileProvider, UserProfileProvider>();

            builder.AddSingleton <IConfiguration>(config);

            builder
            .AddSingleton <IProviderVersionService, ProviderVersionService>()
            .AddSingleton <IHealthChecker, ProviderVersionService>();

            builder
            .AddSingleton <IProviderSnapshotDataLoadService, ProviderSnapshotDataLoadService>()
            .AddSingleton <IHealthChecker, ProviderSnapshotDataLoadService>();

            builder
            .AddSingleton <IScopedProvidersService, ScopedProvidersService>()
            .AddSingleton <IHealthChecker, ScopedProvidersService>();

            builder
            .AddSingleton <IProviderVersionUpdateCheckService, ProviderVersionUpdateCheckService>();

            builder
            .AddSingleton <IProvidersApiClient, ProvidersApiClient>();

            builder
            .AddSingleton <IJobManagement, JobManagement>();

            builder.AddJobsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddSpecificationsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddResultsInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddFundingDataServiceInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);
            builder.AddPoliciesInterServiceClient(config, handlerLifetime: Timeout.InfiniteTimeSpan);

            builder.AddSingleton <IDeadletterService, DeadletterService>();

            builder.AddCaching(config);

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

            builder.AddFeatureToggling(config);

            MapperConfiguration providerVersionsConfig = new MapperConfiguration(c =>
            {
                c.AddProfile <ProviderVersionsMappingProfile>();
            });

            builder
            .AddSingleton(providerVersionsConfig.CreateMapper());

            builder
            .AddSingleton <IFileSystemCache, FileSystemCache>()
            .AddSingleton <IFileSystemAccess, FileSystemAccess>()
            .AddSingleton <IFileSystemCacheSettings, FileSystemCacheSettings>();

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

            builder
            .AddSingleton <IProviderVersionServiceSettings>(ctx =>
            {
                ProviderVersionServiceSettings settings = new ProviderVersionServiceSettings();

                config.Bind("providerversionservicesettings", settings);

                return(settings);
            });

            builder
            .AddSingleton <IScopedProvidersServiceSettings>(ctx =>
            {
                ScopedProvidersServiceSettings settings = new ScopedProvidersServiceSettings();

                config.Bind("scopedprovidersservicesetting", settings);

                return(settings);
            });

            PolicySettings              policySettings             = ServiceCollectionExtensions.GetPolicySettings(config);
            AsyncBulkheadPolicy         totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings);
            ProvidersResiliencePolicies resiliencePolicies         = CreateResiliencePolicies(totalNetworkRequestsPolicy);

            builder.AddSingleton <IJobManagementResiliencePolicies>(resiliencePolicies);

            builder.AddSingleton <IProvidersResiliencePolicies>(resiliencePolicies);

            builder.AddSingleton <IValidator <ProviderVersionViewModel>, UploadProviderVersionValidator>();

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

                config.Bind("AzureStorageSettings", storageSettings);

                storageSettings.ContainerName = "providerversions";

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

            builder.AddSingleton <IProviderVersionsMetadataRepository, ProviderVersionsMetadataRepository>(
                ctx =>
            {
                CosmosDbSettings specRepoDbSettings = new CosmosDbSettings();

                config.Bind("CosmosDbSettings", specRepoDbSettings);

                specRepoDbSettings.ContainerName = "providerversionsmetadata";

                CosmosRepository cosmosRepository = new CosmosRepository(specRepoDbSettings);

                return(new ProviderVersionsMetadataRepository(cosmosRepository));
            });

            builder.AddServiceBus(config, "providers");

            builder.AddScoped <IUserProfileProvider, UserProfileProvider>();

            return(builder.BuildServiceProvider());
        }