|
9 | 9 | using ServiceLayer.Mesh.Messaging; |
10 | 10 | using ServiceLayer.Data; |
11 | 11 | using ServiceLayer.Mesh.Storage; |
| 12 | +using ServiceLayer.Common; |
12 | 13 |
|
13 | 14 | var host = new HostBuilder() |
14 | 15 | .ConfigureFunctionsWebApplication() |
15 | 16 | .ConfigureServices(services => |
16 | 17 | { |
17 | | - var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); |
| 18 | + var environment = EnvironmentVariables.GetRequired("ASPNETCORE_ENVIRONMENT"); |
18 | 19 | var isLocalEnvironment = environment == "Development"; |
19 | 20 |
|
20 | 21 | // MESH Client config |
21 | 22 | services |
22 | | - .AddMeshClient(_ => _.MeshApiBaseUrl = Environment.GetEnvironmentVariable("MeshApiBaseUrl")) |
23 | | - .AddMailbox(Environment.GetEnvironmentVariable("NbssMailboxId"), new NHS.MESH.Client.Configuration.MailboxConfiguration |
| 23 | + .AddMeshClient(_ => _.MeshApiBaseUrl = EnvironmentVariables.GetRequired("MeshApiBaseUrl")) |
| 24 | + .AddMailbox(EnvironmentVariables.GetRequired("NbssMailboxId"), new NHS.MESH.Client.Configuration.MailboxConfiguration |
24 | 25 | { |
25 | | - Password = Environment.GetEnvironmentVariable("MeshPassword"), |
26 | | - SharedKey = Environment.GetEnvironmentVariable("MeshSharedKey"), |
| 26 | + Password = EnvironmentVariables.GetRequired("MeshPassword"), |
| 27 | + SharedKey = EnvironmentVariables.GetRequired("MeshSharedKey"), |
27 | 28 | }).Build(); |
28 | 29 |
|
29 | 30 | // EF Core DbContext |
30 | 31 | services.AddDbContext<ServiceLayerDbContext>(options => |
31 | 32 | { |
32 | | - var connectionString = Environment.GetEnvironmentVariable("DatabaseConnectionString"); |
| 33 | + var connectionString = EnvironmentVariables.GetRequired("DatabaseConnectionString"); |
33 | 34 | if (string.IsNullOrEmpty(connectionString)) |
34 | 35 | throw new InvalidOperationException("The connection string has not been initialized."); |
35 | 36 |
|
36 | 37 | options.UseSqlServer(connectionString); |
37 | 38 | }); |
38 | 39 |
|
| 40 | + var queueClientOptions = new QueueClientOptions |
| 41 | + { |
| 42 | + MessageEncoding = QueueMessageEncoding.Base64 |
| 43 | + }; |
| 44 | + |
39 | 45 | // Register QueueClients as singletons |
40 | 46 | services.AddSingleton(provider => |
41 | 47 | { |
42 | 48 | if (isLocalEnvironment) |
43 | 49 | { |
44 | | - var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); |
45 | | - return new QueueServiceClient(connectionString, new QueueClientOptions |
46 | | - { |
47 | | - MessageEncoding = QueueMessageEncoding.Base64 |
48 | | - }); |
| 50 | + var connectionString = EnvironmentVariables.GetRequired("AzureWebJobsStorage"); |
| 51 | + return new QueueServiceClient(connectionString, queueClientOptions); |
49 | 52 | } |
50 | 53 |
|
51 | | - var meshStorageAccountUrl = Environment.GetEnvironmentVariable("MeshStorageAccountUrl"); |
52 | | - return new QueueServiceClient(new Uri(meshStorageAccountUrl), new DefaultAzureCredential(), new QueueClientOptions |
53 | | - { |
54 | | - MessageEncoding = QueueMessageEncoding.Base64 |
55 | | - }); |
| 54 | + var meshStorageAccountUrl = EnvironmentVariables.GetRequired("MeshStorageAccountUrl"); |
| 55 | + return new QueueServiceClient(new Uri(meshStorageAccountUrl), new DefaultAzureCredential(), queueClientOptions); |
56 | 56 | }); |
57 | 57 |
|
58 | 58 | services.AddSingleton<IFileExtractQueueClient, FileExtractQueueClient>(); |
59 | 59 | services.AddSingleton<IFileTransformQueueClient, FileTransformQueueClient>(); |
60 | 60 |
|
61 | 61 | services.AddSingleton(provider => |
62 | 62 | { |
63 | | - var client = new BlobContainerClient( |
64 | | - Environment.GetEnvironmentVariable("AzureWebJobsStorage"), |
65 | | - Environment.GetEnvironmentVariable("BlobContainerName")); |
66 | | - client.CreateIfNotExistsAsync(); |
67 | | - // might wanna make this async |
68 | | - return client; |
| 63 | + return new BlobContainerClient( |
| 64 | + EnvironmentVariables.GetRequired("AzureWebJobsStorage"), |
| 65 | + EnvironmentVariables.GetRequired("BlobContainerName")); |
69 | 66 | }); |
70 | 67 |
|
71 | 68 | services.AddSingleton<IMeshFilesBlobStore, MeshFilesBlobStore>(); |
|
0 commit comments