-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
84 lines (59 loc) · 2.4 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
75
76
77
78
79
80
81
82
83
84
using Bet.AspNetCore.Middleware.Diagnostics;
using Bet.Extensions.Resilience.Http.Options;
using Bet.Extensions.Resilience.WebApp.Sample.Clients;
using Bet.Extensions.Resilience.WebApp.Sample.Models;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseResilienceOnStartup();
builder.Services.AddDeveloperListRegisteredServices(o =>
{
o.PathOutputOptions = PathOutputOptions.Json;
});
builder.Services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
});
builder.Services.AddControllers();
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
// https://docs.microsoft.com/sr-latn-rs/aspnet/core/mvc/views/view-compilation?view=aspnetcore-3.0
// https://github.com/aspnet/Announcements/issues/343
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
// services
// .AddResilienceHttpClient<BibleClient, BibleClient>()
// .ConfigureDefaultPolicies();
builder.Services.AddHttpDefaultResiliencePolicies(sectionName: "DefaultHttpPolicies");
builder.Services
.AddHttpClient<IBibleClient, BibleClient>(nameof(BibleClient))
// configurations for options becomes IChavahClient
.ConfigureOptions<BibleClientOptions>()
.AddPolicyHandlerFromRegistry(HttpPolicyOptionsKeys.HttpCircuitBreakerPolicy)
.AddPolicyHandlerFromRegistry(HttpPolicyOptionsKeys.HttpRetryPolicy);
builder.Services.AddSingleton<ThrowModel>();
builder.Services
.AddHttpClient<IThrowClient, ThrowClient>(nameof(ThrowClient))
.ConfigureOptions<ThrowClientOptions>()
.AddPolicyHandlerFromRegistry(HttpPolicyOptionsKeys.HttpCircuitBreakerPolicy)
.AddPolicyHandlerFromRegistry(HttpPolicyOptionsKeys.HttpRetryPolicy);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDeveloperListRegisteredServices();
}
else
{
app.UseExceptionHandler("/Home/Error");
// 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.UseCookiePolicy();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
await app.RunAsync();