// Program.csusingaspire_cache_redis.Web;usingaspire_cache_redis.Web.Components;var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.AddRedisOutputCache("cache");
builder.Services.AddHttpClient<WeatherApiClient>(client =>{// This URL uses "https+http://" to indicate HTTPS is preferred over HTTP.// Learn more about service discovery scheme resolution at https://aka.ms/dotnet/sdschemes.
client.BaseAddress =new("https+http://aspire-cache-redis-apiservice");});// Add services to the container.
builder.Services.AddRazorComponents().AddInteractiveServerComponents();var app = builder.Build();
app.MapDefaultEndpoints();// Configure the HTTP request pipeline.if(!app.Environment.IsDevelopment()){
app.UseExceptionHandler("/Error",createScopeForErrors:true);// 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.UseOutputCache();
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
app.Run();
//Home.razor
@page "/"
@using Microsoft.AspNetCore.OutputCaching
@attribute [OutputCache(Duration =10)]<PageTitle>Home</PageTitle><h1>Hello, world!</h1>
Welcome to your new app on @DateTime.Now
//Weather.razor
@page "/weather"
@using Microsoft.AspNetCore.OutputCaching
@attribute [StreamRendering(true)]
@attribute [OutputCache(Duration =10)]
@inject WeatherApiClient WeatherApi
<PageTitle>Weather</PageTitle><h1>Weather @DateTime.Now</h1><p>This component demonstrates showing data loaded from a backend API service.</p>
@if(forecasts ==null){<p><em>Loading...</em></p>}else{<table class="table"><thead><tr><th>Date</th><th>Temp.(C)</th><th>Temp.(F)</th><th>Summary</th></tr></thead><tbody>
@foreach(var forecast in forecasts){<tr><td>@forecast.Date.ToShortDateString()</td><td>@forecast.TemperatureC</td><td>@forecast.TemperatureF</td><td>@forecast.Summary</td></tr>}</tbody></table>}
@code {privateWeatherForecast[]? forecasts;protectedoverrideasyncTaskOnInitializedAsync(){
forecasts =await WeatherApi.GetWeatherAsync();}}