-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
38 lines (30 loc) · 1 KB
/
Program.cs
File metadata and controls
38 lines (30 loc) · 1 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
using Microsoft.EntityFrameworkCore;
using TaskTimer.Data;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
// Add services
builder.Services.AddControllersWithViews()
.AddJsonOptions(options =>
{
// Convert enums to strings in JSON
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.JsonSerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
});
builder.Services.AddDbContext<AlertContext>(options =>
options.UseInMemoryDatabase("AlertsDb"));
var app = builder.Build();
// Ensure database is created
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<AlertContext>();
context.Database.EnsureCreated();
}
// Configure pipeline
app.UseStaticFiles();
app.UseRouting();
// Map routes
app.MapControllers();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();