-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-tables.cs
More file actions
executable file
·42 lines (35 loc) · 1.38 KB
/
azure-tables.cs
File metadata and controls
executable file
·42 lines (35 loc) · 1.38 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
// Program.cs
builder.Services.AddSingleton<AzureConnectors>();
// AzureConnectors.cs
public class AzureConnectors
{
private readonly Lazy<TableServiceClient> _tableServiceClient;
public TableServiceClient TableServiceClient => _tableServiceClient.Value;
public TableClient GetTableClient(string tableName) => TableServiceClient.GetTableClient(tableName);
public AzureConnectors(IConfiguration configuration, ILogger<AzureConnectors> logger)
{
_tableServiceClient = new(() =>
{
logger.LogInformation("Initialized TableServiceClient");
return new TableServiceClient(configuration.GetConnectionString("Storage"));
}, LazyThreadSafetyMode.ExecutionAndPublication);
}
}
// AuditTableStorage.cs
public class AuditTableStorage
{
private readonly AzureConnectors _azureConnectors;
public AuditTableStorage(AzureConnectors azureConnectors)
{
_azureConnectors = azureConnectors;
}
public async Task Add(AuditLogItem log)
{
var tableClient = _azureConnectors.GetTableClient(TableName);
await tableClient.AddEntityAsync(log);
}
}
// appsettings.json
"ConnectionStrings": {
"Storage" : "DefaultEndpointsProtocol=https;AccountName=webinariolocalst;AccountKey=2mX0cYkeCnFhWg7QWaGRe4dcTSo8je+B8H25Y/oErS7aB2x34bBLwfWMkOeVsSA+/YmAMRIAaCZ++AStvMTjew==;EndpointSuffix=core.windows.net"
}