-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (32 loc) · 1.27 KB
/
Program.cs
File metadata and controls
41 lines (32 loc) · 1.27 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
using System.Net.Http.Headers;
using Microsoft.AspNetCore.DataProtection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
// Data Protection (default key-ring is fine here; API key itself is encrypted and stored in SQL)
builder.Services.AddDataProtection().SetApplicationName("MvcWeatherMap");
// Dapper + services
builder.Services.AddSingleton<ISqlConnectionFactory, SqlConnectionFactory>();
builder.Services.AddScoped<ISecretProtector, SecretProtector>();
builder.Services.AddScoped<ISecretRepository, SecretRepository>();
builder.Services.AddScoped<WeatherService>();
// NWS HttpClient
builder.Services.AddHttpClient("nws", c =>
{
c.BaseAddress = new Uri("https://api.weather.gov/");
c.DefaultRequestHeaders.UserAgent.ParseAdd(
builder.Configuration["Nws:UserAgent"] ?? "MvcWeatherMap/1.0 (+contact@example.com)");
c.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/geo+json"));
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();