|
1 | 1 | using Microsoft.Extensions.Hosting; |
2 | 2 | using Microsoft.Extensions.DependencyInjection; |
3 | | -using Azure.Storage.Queues; |
4 | | -using Azure.Identity; |
5 | | -using Microsoft.EntityFrameworkCore; |
6 | 3 | using NHS.MESH.Client; |
7 | | -using Azure.Storage.Blobs; |
| 4 | +using ServiceLayer; |
8 | 5 | using ServiceLayer.Mesh.Configuration; |
9 | 6 | using ServiceLayer.Mesh.Messaging; |
10 | | -using ServiceLayer.Data; |
11 | 7 | using ServiceLayer.Mesh.Storage; |
12 | 8 | using ServiceLayer.Mesh.FileTypes.NbssAppointmentEvents; |
13 | 9 |
|
|
18 | 14 | var environment = EnvironmentVariables.GetRequired("ASPNETCORE_ENVIRONMENT"); |
19 | 15 | var isLocalEnvironment = environment == "Development"; |
20 | 16 |
|
21 | | - // MESH Client config |
22 | | - services |
23 | | - .AddMeshClient(_ => _.MeshApiBaseUrl = EnvironmentVariables.GetRequired("MeshApiBaseUrl")) |
24 | | - .AddMailbox(EnvironmentVariables.GetRequired("NbssMailboxId"), new NHS.MESH.Client.Configuration.MailboxConfiguration |
25 | | - { |
26 | | - Password = EnvironmentVariables.GetRequired("MeshPassword"), |
27 | | - SharedKey = EnvironmentVariables.GetRequired("MeshSharedKey"), |
28 | | - }).Build(); |
| 17 | + ConfigureMeshClient(services); |
29 | 18 |
|
30 | | - // EF Core DbContext |
31 | | - services.AddDbContext<ServiceLayerDbContext>(options => |
32 | | - { |
33 | | - var connectionString = EnvironmentVariables.GetRequired("DatabaseConnectionString"); |
34 | | - if (string.IsNullOrEmpty(connectionString)) |
35 | | - throw new InvalidOperationException("The connection string has not been initialized."); |
36 | | - |
37 | | - options.UseSqlServer(connectionString); |
38 | | - }); |
39 | | - |
40 | | - var queueClientOptions = new QueueClientOptions |
41 | | - { |
42 | | - MessageEncoding = QueueMessageEncoding.Base64 |
43 | | - }; |
44 | | - |
45 | | - // Register QueueClients as singletons |
46 | | - services.AddSingleton(provider => |
47 | | - { |
48 | | - if (isLocalEnvironment) |
49 | | - { |
50 | | - var connectionString = EnvironmentVariables.GetRequired("AzureWebJobsStorage"); |
51 | | - return new QueueServiceClient(connectionString, queueClientOptions); |
52 | | - } |
53 | | - |
54 | | - var meshStorageAccountUrl = EnvironmentVariables.GetRequired("MeshStorageAccountUrl"); |
55 | | - return new QueueServiceClient(new Uri(meshStorageAccountUrl), new DefaultAzureCredential(), queueClientOptions); |
56 | | - }); |
| 19 | + services.AddCommonServices(); |
57 | 20 |
|
58 | | - services.AddSingleton<IFileExtractQueueClient, FileExtractQueueClient>(); |
59 | | - services.AddSingleton<IFileTransformQueueClient, FileTransformQueueClient>(); |
| 21 | + services.AddMessagingServices(isLocalEnvironment); |
| 22 | + services.AddStorageServices(isLocalEnvironment); |
60 | 23 |
|
61 | | - services.AddSingleton(provider => |
62 | | - { |
63 | | - return new BlobContainerClient( |
64 | | - EnvironmentVariables.GetRequired("AzureWebJobsStorage"), |
65 | | - EnvironmentVariables.GetRequired("BlobContainerName")); |
66 | | - }); |
67 | | - |
68 | | - services.AddSingleton<IMeshFilesBlobStore, MeshFilesBlobStore>(); |
69 | | - |
70 | | - services.AddTransient<IFileDiscoveryFunctionConfiguration, AppConfiguration>(); |
71 | | - services.AddTransient<IFileExtractQueueClientConfiguration, AppConfiguration>(); |
72 | | - services.AddTransient<IFileTransformQueueClientConfiguration, AppConfiguration>(); |
73 | | - services.AddTransient<IMeshHandshakeFunctionConfiguration, AppConfiguration>(); |
74 | | - services.AddTransient<IFileRetryFunctionConfiguration, AppConfiguration>(); |
75 | | - services.AddTransient<IFileTransformFunctionConfiguration, AppConfiguration>(); |
76 | | - |
77 | | - services.ConfigureNbssAppointmentEvents(); |
| 24 | + services.AddApplicationConfiguration(); |
| 25 | + services.AddNbssAppointmentEventServices(); |
78 | 26 | }); |
79 | 27 |
|
80 | 28 |
|
|
85 | 33 |
|
86 | 34 | var app = host.Build(); |
87 | 35 | await app.RunAsync(); |
| 36 | +return; |
| 37 | + |
| 38 | +void ConfigureMeshClient(IServiceCollection services) |
| 39 | +{ |
| 40 | + services |
| 41 | + .AddMeshClient(_ => _.MeshApiBaseUrl = EnvironmentVariables.GetRequired("MeshApiBaseUrl")) |
| 42 | + .AddMailbox(EnvironmentVariables.GetRequired("NbssMailboxId"), new NHS.MESH.Client.Configuration.MailboxConfiguration |
| 43 | + { |
| 44 | + Password = EnvironmentVariables.GetRequired("MeshPassword"), |
| 45 | + SharedKey = EnvironmentVariables.GetRequired("MeshSharedKey"), |
| 46 | + }).Build(); |
| 47 | +} |
0 commit comments