Code · 48 lines · 1373 bytes
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
48using MailSharp.WebManager.Extensions;
using MailSharp.WebManager.Services;

var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
	ContentRootPath = AppContext.BaseDirectory
});

builder.Configuration.AddJsonFile(
	Path.Combine(AppContext.BaseDirectory, "mailsharp.json"),
	optional: true,
	reloadOnChange: true);

builder.Services.AddMvcCore();

builder.Services.AddRazorUnderRoot();

builder.Services.AddControllersWithViews()
	.AddJsonOptions(o => o.JsonSerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase);

builder.Services.AddAuthenticationAndAddAuthorization();

builder.Host.UseWindowsService();

builder.Services.AddLogging(logging => logging.AddConsole());

builder.Services.AddMailSharpServices();

var app = builder.Build();

// Seed the override file from appsettings.json defaults for any section that
// is missing or was previously saved with empty values, then reload so the
// seeded values are visible immediately (reloadOnChange is async).
using (var scope = app.Services.CreateScope())
    scope.ServiceProvider.GetRequiredService<ConfigService>().EnsureOverrideInitialized();
(app.Configuration as IConfigurationRoot)?.Reload();

app.UseDefaultFiles();

app.UseStaticFiles();

app.UseAuthenticationAndAddAuthorization();

app.MapDefaultControllerRoute();

app.MapRazorPages();

await app.RunAsync();