-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
75 lines (61 loc) · 2.65 KB
/
Copy pathProgram.cs
File metadata and controls
75 lines (61 loc) · 2.65 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using FluentValidation;
using GitHubClient.Configuration;
using GitHubClient.Middleware;
using GitHubClient.Models.Requests;
using GitHubClient.Services;
using GitHubClient.Validators;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
// --- Serilog ---
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", Serilog.Events.LogEventLevel.Information)
.MinimumLevel.Override("System.Net.Http", Serilog.Events.LogEventLevel.Warning)
.WriteTo.Console(
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}")
.WriteTo.File(
path: "logs/log-.txt",
rollingInterval: RollingInterval.Day,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u3}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}",
retainedFileCountLimit: 30)
.Enrich.FromLogContext()
.CreateLogger();
builder.Host.UseSerilog();
// --- Configuration ---
builder.Services.Configure<ExternalApisOptions>(
builder.Configuration.GetSection(ExternalApisOptions.SectionName));
// --- Named HttpClients ---
builder.Services.AddHttpClient("AuthClient");
builder.Services.AddHttpClient("GitHubClient");
// --- Services ---
builder.Services.AddSingleton<IAuthorizationService, AuthorizationService>();
builder.Services.AddScoped<IGitHubService, GitHubService>();
// --- Validators ---
builder.Services.AddScoped<IValidator<GitHubQueryParameters>, GitHubQueryParametersValidator>();
builder.Services.AddScoped<IValidator<GitHubUserRequest>, GitHubRequestValidator>();
builder.Services.AddScoped<IValidator<GitHubUsernameParameters>, GitHubUsernameParametersValidator>();
builder.Services.AddScoped<IValidator<GitHubUserReposQueryParameters>, GitHubUserReposQueryParametersValidator>();
builder.Services.AddScoped<IValidator<GitHubCreateRepoRequest>, GitHubCreateRepoRequestValidator>();
// --- Controllers & Swagger ---
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "GitHub API Client", Version = "v1" });
});
var app = builder.Build();
// --- Middleware Pipeline ---
app.UseMiddleware<ExceptionHandlingMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapControllers();
app.Run();
/// <summary>
/// Partial class declaration to enable WebApplicationFactory in integration tests.
/// </summary>
public partial class Program { }