Skip to content

Commit 25540f5

Browse files
committed
Clean up Program
1 parent 208005f commit 25540f5

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/Core/Program.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,36 @@ public static void Main(string[] args)
1313
{
1414
var builder = WebApplication.CreateSlimBuilder(args);
1515

16-
builder.Services.AddOptionsWithValidateOnStart<CloudflareOptions>()
17-
.Bind(builder.Configuration.GetSection(CloudflareOptions.Cloudflare));
18-
builder.Services.AddSingleton<IValidateOptions<CloudflareOptions>, CloudflareOptionsValidator>();
16+
AddOptions(builder.Services, builder.Configuration);
1917

20-
builder.Services.AddOptionsWithValidateOnStart<DdnsOptions>()
21-
.Bind(builder.Configuration.GetSection(DdnsOptions.Ddns));
22-
builder.Services.AddSingleton<IValidateOptions<DdnsOptions>, DdnsOptionsValidator>();
23-
24-
builder.Services.AddTransient<CloudflareApiTokenMessageHandler>();
25-
26-
builder.Services.AddHttpClient<CloudflareClient>(o =>
27-
{
28-
o.BaseAddress = new Uri("https://api.cloudflare.com/client/v4/");
29-
})
30-
.AddHttpMessageHandler<CloudflareApiTokenMessageHandler>();
18+
AddCloudflareClient(builder.Services);
3119

3220
var app = builder.Build();
3321

3422
app.MapGet("/update", UpdateHandler.Handle);
3523

3624
app.Run();
3725
}
26+
27+
private static void AddOptions(IServiceCollection services, ConfigurationManager configuration)
28+
{
29+
services.AddOptionsWithValidateOnStart<CloudflareOptions>()
30+
.Bind(configuration.GetSection(CloudflareOptions.Cloudflare));
31+
services.AddSingleton<IValidateOptions<CloudflareOptions>, CloudflareOptionsValidator>();
32+
33+
services.AddOptionsWithValidateOnStart<DdnsOptions>()
34+
.Bind(configuration.GetSection(DdnsOptions.Ddns));
35+
services.AddSingleton<IValidateOptions<DdnsOptions>, DdnsOptionsValidator>();
36+
}
37+
38+
private static void AddCloudflareClient(IServiceCollection services)
39+
{
40+
services.AddTransient<CloudflareApiTokenMessageHandler>();
41+
42+
services.AddHttpClient<CloudflareClient>(o =>
43+
{
44+
o.BaseAddress = new Uri("https://api.cloudflare.com/client/v4/");
45+
})
46+
.AddHttpMessageHandler<CloudflareApiTokenMessageHandler>();
47+
}
3848
}

0 commit comments

Comments
 (0)