-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceRegistration.cs
More file actions
46 lines (40 loc) · 2.15 KB
/
ServiceRegistration.cs
File metadata and controls
46 lines (40 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nhs.Appointments.Core.Inspectors;
using Nhs.Appointments.Core.Sites;
namespace Nhs.Appointments.Core;
public static class ServiceRegistration
{
public static IServiceCollection AddRequestInspectors(this IServiceCollection services)
{
var inspectorTypes = typeof(IRequestInspector).Assembly
.GetTypes()
.Where(t => typeof(IRequestInspector).IsAssignableFrom(t) && t.IsClass && t.IsAbstract == false);
foreach (var type in inspectorTypes)
{
services.AddSingleton(type);
}
return services;
}
public static IServiceCollection ConfigureSiteService(this IServiceCollection services,
IConfiguration configuration)
{
services.Configure<SiteServiceOptions>(opts =>
{
opts.SiteCacheKey = configuration.GetValue("SITE_CACHE_KEY", "sites");
opts.AllSitesSlidingCacheEnabled = configuration.GetValue("ALLSITES_SLIDING_CACHE_ENABLED", true);
opts.AllSitesCacheDurationMinutes = configuration.GetValue("ALLSITES_CACHE_DURATION_MINUTES", 60);
opts.AllSitesSlideCacheDurationMinutes = configuration.GetValue("ALLSITES_SLIDING_CACHE_DURATION_MINUTES", 20);
opts.SiteCacheDurationMinutes = configuration.GetValue("SITE_CACHE_DURATION_MINUTES", 5);
opts.SiteSlideCacheDurationMinutes = configuration.GetValue("SITE_SLIDING_CACHE_DURATION_MINUTES", 1);
opts.DisableSiteCache = configuration.GetValue("DISABLE_SITE_CACHE", false);
//default 4 hours
opts.SiteSupportsServiceSlidingCacheAbsoluteExpirationSeconds = configuration.GetValue("SITE_SUPPORTS_SERVICE_SLIDING_CACHE_ABSOLUTE_EXPIRATION_SECONDS", 14400);
//default 15 mins
opts.SiteSupportsServiceSlidingCacheSlideThresholdSeconds = configuration.GetValue("SITE_SUPPORTS_SERVICE_SLIDING_CACHE_SLIDE_THRESHOLD_SECONDS", 900);
//default x2
opts.SiteSupportsServiceBatchMultiplier = configuration.GetValue("SITE_SUPPORTS_SERVICE_BATCH_MULTIPLIER", 2);
});
return services;
}
}