This repository was archived by the owner on Jul 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (44 loc) · 1.83 KB
/
Program.cs
File metadata and controls
50 lines (44 loc) · 1.83 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
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFluentUIComponents();
builder.Services.AddHttpClient();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
var sqlServerConnectionString = builder.Configuration.GetConnectionString("SqlServerConnection");
var redisCacheConnectionString = builder.Configuration.GetConnectionString("RedisCache");
var env = builder.Environment.EnvironmentName;
if (string.IsNullOrWhiteSpace(sqlServerConnectionString))
{
// The application configuration does not include a database connection string, use Testcontainers for .NET to create, start and seed the dependent database.
builder.Services.AddSingleton<DatabaseContainer>();
builder.Services.AddHostedService(services => services.GetRequiredService<DatabaseContainer>());
builder.Services.AddDbContext<WeatherDataContext>((services, options) =>
{
var databaseContainer = services.GetRequiredService<DatabaseContainer>();
options.UseSqlServer(databaseContainer.GetConnectionString());
});
}
else
{
// The application configuration includes a database connection string, use it to establish a connection and seed the database.
builder.Services.AddDbContext<WeatherDataContext>((_, options) => options.UseSqlServer(sqlServerConnectionString));
}
builder.Services.AddScoped<IWeatherDataReadOnlyRepository, WeatherDataReadOnlyContext>();
builder.Services.AddScoped<IWeatherDataWriteOnlyRepository, WeatherDataWriteOnlyContext>();
builder.Services.AddScoped<ISearchCityOrZipCode, SearchCityOrZipCode>();
var app = builder.Build();
app.UseExceptionHandler("/Error");
app.UseHsts();
app.UseHttpsRedirection();
app.UseRouting();
app.UseStaticFiles();
app.MapControllers();
app.MapRazorPages();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
namespace WeatherForecast
{
public sealed class Program
{
}
}