-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (43 loc) · 1.82 KB
/
Program.cs
File metadata and controls
60 lines (43 loc) · 1.82 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using DataServices.Core;
using HealthChecks.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Common;
using NHS.CohortManager.DemographicServices;
using DataServices.Database;
using Microsoft.Extensions.Logging;
using System.Security.Cryptography.X509Certificates;
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
var logger = loggerFactory.CreateLogger("Program");
var host = new HostBuilder();
logger.LogInformation("Application Has Started");
// Load configuration
host.AddConfiguration<ManageNemsSubscriptionConfig>(out ManageNemsSubscriptionConfig config);
var nemsConfig = config;
X509Certificate2 nemsCertificate;
// Load NEMS certificate up-front and inject into DI
nemsCertificate = await nemsConfig.LoadNemsCertificateAsync(logger);
host.ConfigureFunctionsWebApplication();
host.AddHttpClient()
.AddNemsHttpClient(nemsConfig.IsStubbed)
.ConfigureServices(services =>
{
// Register NEMS certificate
services.AddSingleton(nemsCertificate);
// Register NEMS subscription manager
services.AddScoped<NemsSubscriptionManager>();
// Register response helpers
services.AddSingleton<ICreateResponse, CreateResponse>();
// Register health checks
services.AddDatabaseHealthCheck("NEMSSubscription");
// Log configuration for debugging (without sensitive data)
logger.LogInformation("NEMS Configuration loaded - Endpoint: {Endpoint}, ODS: {OdsCode}, MESH: {MeshId}",
nemsConfig.NemsFhirEndpoint,
nemsConfig.NemsOdsCode,
string.IsNullOrEmpty(nemsConfig.NemsMeshMailboxId) ? "NOT_SET" : "SET");
})
.AddDataServicesHandler<DataServicesContext>()
.AddTelemetry()
.AddExceptionHandler();
var app = host.Build();
await app.RunAsync();