-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
executable file
·55 lines (46 loc) · 1.59 KB
/
Program.cs
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.Identity;
using Microsoft.EntityFrameworkCore;
using SimpleTodo.Api;
var builder = WebApplication.CreateBuilder(args);
var credential = new DefaultAzureCredential();
string keyVaultEndpoint = builder.Configuration["AZURE_KEY_VAULT_ENDPOINT"];
Console.WriteLine($"keyVaultEndpoint: {keyVaultEndpoint}");
builder.Configuration.AddAzureKeyVault(new Uri(keyVaultEndpoint), credential);
builder.Services.AddScoped<ListsRepository>();
builder.Services.AddDbContext<TodoDb>(options =>
{
var connectionString = builder.Configuration[builder.Configuration["AZURE_SQL_CONNECTION_STRING_KEY"]];
Console.WriteLine($"connectionString: {connectionString}");
options.UseSqlServer(connectionString, sqlOptions => sqlOptions.EnableRetryOnFailure());
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors();
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration);
var app = builder.Build();
await using (var scope = app.Services.CreateAsyncScope())
{
var db = scope.ServiceProvider.GetRequiredService<TodoDb>();
await db.Database.EnsureCreatedAsync();
}
app.UseCors(policy =>
{
policy.AllowAnyOrigin();
policy.AllowAnyHeader();
policy.AllowAnyMethod();
});
// Swagger UI
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("./openapi.yaml", "v1");
options.RoutePrefix = "";
});
app.UseStaticFiles(new StaticFileOptions
{
// Serve openapi.yaml file
ServeUnknownFileTypes = true,
});
app.MapGroup("/lists")
.MapTodoApi()
.WithOpenApi();
app.Run();