-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (44 loc) · 1.54 KB
/
Program.cs
File metadata and controls
60 lines (44 loc) · 1.54 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
56
57
58
59
60
using commityourcode_minimal_api.Extensions;
using Microsoft.EntityFrameworkCore;
using commityourcode_minimal_api.Data;
using commityourcode_minimal_api.Services;
using commityourcode_minimal_api.Endpoints.Customer;
var builder = WebApplication.CreateBuilder(args);
//custom extension method to configure open api. so that program.cs is cleaner
builder.Services.ConfigureOpenApi();
//create a sql lite db in the root folder
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite("Data Source=MinApiDemo.db"));
builder.Services.AddScoped<ICustomerService, CustomerService>();
builder.Services.AddValidation();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
await DataUtility.ManageDataAsync(scope.ServiceProvider);
}
app.UseHttpsRedirection();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");
app.UseStaticFiles();
app.MapScalar();
app.MapCustomerEndpoints();
app.Run();
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}