This repository was archived by the owner on Jul 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (52 loc) · 2.27 KB
/
Program.cs
File metadata and controls
61 lines (52 loc) · 2.27 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
61
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Azure.Storage.Queues;
using Azure.Identity;
using Microsoft.EntityFrameworkCore;
using NHS.MESH.Client;
using ServiceLayer.Mesh.Data;
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
// MESH Client config
services
.AddMeshClient(_ => _.MeshApiBaseUrl = Environment.GetEnvironmentVariable("MeshApiBaseUrl"))
.AddMailbox(Environment.GetEnvironmentVariable("BSSMailBox"), new NHS.MESH.Client.Configuration.MailboxConfiguration
{
Password = Environment.GetEnvironmentVariable("MeshPassword"),
SharedKey = Environment.GetEnvironmentVariable("MeshSharedKey"),
}).Build();
// EF Core DbContext
services.AddDbContext<ServiceLayerDbContext>(options =>
{
var connectionString = Environment.GetEnvironmentVariable("DatabaseConnectionString");
if (string.IsNullOrEmpty(connectionString))
throw new InvalidOperationException("The connection string has not been initialized.");
options.UseSqlServer(connectionString);
});
// Register QueueClient as singleton
services.AddSingleton(provider =>
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var queueUrl = Environment.GetEnvironmentVariable("QueueUrl");
if (string.IsNullOrWhiteSpace(queueUrl))
throw new InvalidOperationException("QueueUrl environment variable is not set.");
if (environment == "Development")
{
return new QueueClient("UseDevelopmentStorage=true", "my-local-queue");
}
else
{
var credential = new ManagedIdentityCredential();
return new QueueClient(new Uri(queueUrl), credential);
}
});
});
// Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4.
// builder.Services
// .AddApplicationInsightsTelemetryWorkerService()
// .ConfigureFunctionsApplicationInsights();
var app = host.Build();
await app.RunAsync();