- Add shared HealthResponse DTO in ChatAgent.Shared - Add HealthController API endpoint with CORS policy for localhost:5200 - Add ChatApiClient typed HttpClient wrapper in WASM client - Update Home.razor to display health check result on load - Simplify MainLayout to minimal centered layout - Add global imports for Services and Shared.Models - Replace app.css with clean Phase 1 light theme styles - Remove unused OpenAPI package from API project - All files include tutorial-style inline comments (CODE-01)
48 lines
2.3 KiB
C#
48 lines
2.3 KiB
C#
// Program.cs -- Blazor WebAssembly application entry point for ChatAgent.
|
|
//
|
|
// This is where the WASM client is configured and launched. Unlike a server-side
|
|
// ASP.NET Core app, a Blazor WASM app runs entirely in the browser. The
|
|
// WebAssemblyHostBuilder configures:
|
|
// - Root components (what gets rendered into the HTML page)
|
|
// - Services (dependency injection container, similar to server-side DI)
|
|
// - Configuration (reads from wwwroot/appsettings.json)
|
|
//
|
|
// This file will grow as we add more services in later phases (e.g., chat state management).
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
|
using ChatAgent.Client;
|
|
using ChatAgent.Client.Services;
|
|
|
|
var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|
|
|
// Add<App>("#app") tells Blazor to render the App component inside the
|
|
// <div id="app"> element in wwwroot/index.html. This is the "mount point"
|
|
// for the entire Blazor component tree.
|
|
builder.RootComponents.Add<App>("#app");
|
|
|
|
// HeadOutlet allows Razor components to modify <head> elements (e.g., <title>)
|
|
// using the <PageTitle> and <HeadContent> components. "head::after" means
|
|
// content is appended after existing head elements.
|
|
builder.RootComponents.Add<HeadOutlet>("head::after");
|
|
|
|
// Read the API base URL from configuration.
|
|
// In Blazor WASM, configuration comes from wwwroot/appsettings.json.
|
|
// IMPORTANT: wwwroot/ files are PUBLIC -- they are downloaded to the browser.
|
|
// Never put secrets (API keys, passwords) in appsettings.json for a WASM app.
|
|
// The API key lives server-side in the ChatAgent.Api project.
|
|
var apiBaseUrl = builder.Configuration["ApiBaseUrl"] ?? "https://localhost:7100";
|
|
|
|
// AddHttpClient<ChatApiClient> registers a typed HttpClient using IHttpClientFactory.
|
|
// IHttpClientFactory manages the underlying HttpMessageHandler lifetime to prevent
|
|
// socket exhaustion (a common problem with raw HttpClient in long-running apps).
|
|
// The lambda configures the client with the API base URL so ChatApiClient
|
|
// does not need to know the URL -- it is injected with a pre-configured HttpClient.
|
|
// In Blazor WASM, HttpClient uses the browser's Fetch API under the hood.
|
|
builder.Services.AddHttpClient<ChatApiClient>(client =>
|
|
{
|
|
client.BaseAddress = new Uri(apiBaseUrl);
|
|
});
|
|
|
|
await builder.Build().RunAsync();
|