-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
74 lines (59 loc) · 1.99 KB
/
Program.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Blazored.LocalStorage;
using GithubStarSearch;
using GithubStarSearch.Components;
using GithubStarSearch.Searching;
using MudBlazor;
using MudBlazor.Services;
using Octokit;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
// Add serilog
builder.Services.AddSerilog(x => x
.Enrich.FromLogContext()
.WriteTo.Console(
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}"));
// Add MudBlazor services
builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.TopLeft;
});
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.UseMinimalHttpLogger();
// Application logic services
builder.Services.AddScoped<GitHubClient>(x =>
{
var configuration = x.GetRequiredService<IConfiguration>();
var logger = x.GetRequiredService<ILogger<Program>>();
var token = configuration["Github:FineGrainedToken"];
var client = new GitHubClient(new ProductHeaderValue("GithubStarSearch"));
if (string.IsNullOrEmpty(token))
{
logger.LogCritical("No Github:FineGrainedToken found in configuration");
}
else
{
client.Credentials = new Credentials(token);
}
return client;
});
builder.AddMeilisearch();
builder.Services.AddBlazoredLocalStorage();
builder.Services.AddHostedService<RepositoryUpdater>();
builder.Services.AddHostedService<StarsUpdater>();
var app = builder.Build();
app.UseSerilogRequestLogging();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();