Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (48 loc) · 2.87 KB
/
Copy pathProgram.cs
File metadata and controls
55 lines (48 loc) · 2.87 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
using Azure.Data.Tables;
using Azure.Identity;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MW_GC.EventManager.API.Services;
using MW_GC.EventManager.Shared.Entities;
var builder = FunctionsApplication.CreateBuilder(args);
builder.ConfigureFunctionsWebApplication();
builder.Services.AddSingleton(CreateTableServiceClient());
builder.Services.AddSingleton(sp =>
new TableStore<GameEntity>(sp.GetRequiredService<TableServiceClient>(), "Games", "Game"));
builder.Services.AddSingleton(sp =>
new TableStore<ActivityEntity>(sp.GetRequiredService<TableServiceClient>(), TableNames.Activities, TableNames.ActivityPartition));
builder.Services.AddSingleton(sp =>
new TableStore<EventEntity>(sp.GetRequiredService<TableServiceClient>(), "Events", "Event"));
builder.Services.AddSingleton(sp =>
new TableStore<ThemeEntity>(sp.GetRequiredService<TableServiceClient>(), "Themes", "Theme"));
builder.Services.AddSingleton(sp =>
new TableStore<HolidayEntity>(sp.GetRequiredService<TableServiceClient>(), "Holidays", "Holiday"));
// Event metrics (#134, ADR 0001): one row per Event, keyed by the Event id.
builder.Services.AddSingleton(sp =>
new TableStore<EventMetricsEntity>(sp.GetRequiredService<TableServiceClient>(), "EventMetrics", "Metrics"));
builder.Services.AddSingleton(sp =>
new TableStore<CommentEntity>(sp.GetRequiredService<TableServiceClient>(), TableNames.Comments, TableNames.CommentPartition));
// Each old Activity text becomes that Activity's first Comment (#130), once: in the background at host
// start, and before any Activity PUT until the pass has finished (#133).
builder.Services.AddSingleton<ActivityNoteConversion>();
builder.Services.AddHostedService<ActivityNoteConversionStartup>();
// The anonymous Event feedback page (#101): its own tables, and a per-instance like rate limit.
builder.Services.AddSingleton<FeedbackStore>();
builder.Services.AddSingleton(new LikeRateLimiter(TimeProvider.System));
builder.Build().Run();
// Builds the Table Storage client from the AzureWebJobsStorage configuration. Prefers the
// identity-based scheme (AzureWebJobsStorage__accountName + managed identity) used in Azure;
// falls back to a connection string (e.g. Azurite "UseDevelopmentStorage=true") for local dev.
static TableServiceClient CreateTableServiceClient()
{
var accountName = Environment.GetEnvironmentVariable("AzureWebJobsStorage__accountName");
if (!string.IsNullOrWhiteSpace(accountName))
{
var endpoint = new Uri($"https://{accountName}.table.core.windows.net");
return new TableServiceClient(endpoint, new DefaultAzureCredential());
}
var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage") ?? "UseDevelopmentStorage=true";
return new TableServiceClient(connectionString);
}