-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (40 loc) · 1.24 KB
/
Program.cs
File metadata and controls
44 lines (40 loc) · 1.24 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
using Microsoft.EntityFrameworkCore;
using Platform;
using Platform.Models;
using Platform.Services;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddDistributedSqlServerCache(opts =>
{
opts.ConnectionString = builder.Configuration["ConnectionStrings:CacheConnection"];
opts.SchemaName = "dbo";
opts.TableName = "DataCache";
});
builder.Services.AddResponseCaching();
builder.Services.AddSingleton<IResponseFormatter, HtmlResponseFormatter>();
builder.Services.AddDbContext<CalculationContext>(opts =>
{
opts.UseSqlServer(builder.Configuration["ConnectionStrings:CalcConnection"]);
opts.EnableSensitiveDataLogging();
});
builder.Services.AddTransient<SeedData>();
WebApplication app = builder.Build();
app.UseResponseCaching();
app.MapEndpoint<SumEndpoint>("/sum/{count:int=1000000000}");
app.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World");
});
bool cmdLineInit = (app.Configuration["INITDB"] ?? "false") == "true";
if (app.Environment.IsDevelopment() || cmdLineInit)
{
SeedData seedData = app
.Services
.CreateScope()
.ServiceProvider
.GetRequiredService<SeedData>();
seedData.SeedDatabase();
}
if (!cmdLineInit)
{
app.Run();
}