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()); }
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(); }
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 <OnJobNotification>(); builder.AddScoped <OnCheckForJobTimeout>(); } builder.AddSingleton <IUserProfileProvider, UserProfileProvider>(); builder.AddSingleton <IJobManagementService, JobManagementService>(); builder .AddSingleton <IValidator <JobDefinition>, JobDefinitionValidator>(); builder. AddSingleton <IValidator <CreateJobValidationModel>, CreateJobValidator>(); builder .AddSingleton <IJobRepository, JobRepository>((ctx) => { CosmosDbSettings cosmosDbSettings = new CosmosDbSettings(); config.Bind("CosmosDbSettings", cosmosDbSettings); cosmosDbSettings.ContainerName = "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.ContainerName = "jobdefinitions"; CosmosRepository jobDefinitionsCosmosRepostory = new CosmosRepository(cosmosDbSettings); return(new JobDefinitionsRepository(jobDefinitionsCosmosRepostory)); }); builder.AddServiceBus(config, "jobs"); builder.AddPolicySettings(config); builder.AddCaching(config); builder.AddSingleton <IJobsResiliencePolicies>((ctx) => { PolicySettings policySettings = ctx.GetService <PolicySettings>(); AsyncBulkheadPolicy totalNetworkRequestsPolicy = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsPolicy(policySettings); BulkheadPolicy totalNetworkRequestsPolicyNonAsync = ResiliencePolicyHelpers.GenerateTotalNetworkRequestsNonAsyncPolicy(policySettings); return(new ResiliencePolicies { JobDefinitionsRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), CacheProviderPolicy = ResiliencePolicyHelpers.GenerateRedisPolicy(totalNetworkRequestsPolicy), JobRepository = CosmosResiliencePolicyHelper.GenerateCosmosPolicy(totalNetworkRequestsPolicy), MessengerServicePolicy = ResiliencePolicyHelpers.GenerateMessagingPolicy(totalNetworkRequestsPolicy) }); }); builder.AddApplicationInsightsServiceName(config, "CalculateFunding.Functions.Jobs"); builder.AddApplicationInsightsTelemetryClient(config, "CalculateFunding.Functions.Jobs"); builder.AddLogging("CalculateFunding.Functions.Jobs"); builder.AddTelemetry(); builder.AddScoped <IUserProfileProvider, UserProfileProvider>(); return(builder.BuildServiceProvider()); }