-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (26 loc) · 986 Bytes
/
Copy pathProgram.cs
File metadata and controls
35 lines (26 loc) · 986 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
using GoogleMapsApi;
using Samples.Blazor.Geocoding.Components;
using Samples.Blazor.Geocoding.Services;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
// Register the instance-based client with IHttpClientFactory (the recommended pattern).
builder.Services.AddHttpClient<IGoogleMapsClient, GoogleMapsClient>();
builder.Services.AddScoped<GeocodingService>(sp =>
{
string? apiKey = Environment.GetEnvironmentVariable("GOOGLE_API_KEY")
?? builder.Configuration["GoogleApiKey"];
return new GeocodingService(sp.GetRequiredService<IGoogleMapsClient>(), apiKey);
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();