Clone, run, and explore this sample
The app consists of four .NET services:
The entry point that composes every resource and dependency in this sample's distributed application.
var builder = DistributedApplication.CreateBuilder(args);
var postgres = builder.AddPostgres("postgres") .WithPgAdmin() .WithLifetime(ContainerLifetime.Persistent);
if (builder.ExecutionContext.IsRunMode){ // Data volumes don't work on ACA for Postgres so only add when running postgres.WithDataVolume();}
var catalogDb = postgres.AddDatabase("catalogdb");
var basketCache = builder.AddRedis("basketcache") .WithDataVolume() .WithRedisCommander();
var catalogDbManager = builder.AddProject<Projects.AspireShop_CatalogDbManager>("catalogdbmanager") .WithReference(catalogDb) .WaitFor(catalogDb) .WithHttpHealthCheck("/health") .WithHttpCommand("/reset-db", "Reset Database", commandOptions: new() { IconName = "DatabaseLightning" });
var catalogService = builder.AddProject<Projects.AspireShop_CatalogService>("catalogservice") .WithReference(catalogDb) .WaitFor(catalogDbManager) .WithHttpHealthCheck("/health");
var basketService = builder.AddProject<Projects.AspireShop_BasketService>("basketservice") .WithReference(basketCache) .WaitFor(basketCache);
builder.AddProject<Projects.AspireShop_Frontend>("frontend") .WithExternalHttpEndpoints() .WithUrlForEndpoint("https", url => url.DisplayText = "Online Store (HTTPS)") .WithUrlForEndpoint("http", url => url.DisplayText = "Online Store (HTTP)") .WithHttpHealthCheck("/health") .WithReference(basketService) .WithReference(catalogService) .WaitFor(catalogService);
builder.Build().Run();The app consists of four .NET services:
- AspireShop.Frontend: This is an ASP.NET Core Blazor app that displays a paginated catalog of products and allows users to add products to a shopping cart.
- AspireShop.CatalogService: This is an HTTP API that provides access to the catalog of products stored in a PostgreSQL database.
- AspireShop.CatalogDbManager: This is an HTTP API that manages the initialization and updating of the catalog database.
- AspireShop.BasketService: This is a gRPC service that provides access to the shopping cart stored in Redis.
The app also includes a .NET class library project, AspireShop.ServiceDefaults, that contains the code-based defaults used by the .NET service projects.
Prerequisites
Section titled PrerequisitesRunning the app
Section titled Running the appIf using the Aspire CLI, run aspire run from this directory.
If using VS Code, open this directory as a workspace and launch the AspireShop.AppHost project using either the Aspire or C# debuggers.
If using Visual Studio, open the solution file AspireShop.slnx and launch/debug the AspireShop.AppHost project.
If using the .NET CLI, run dotnet run from the AspireShop.AppHost directory.
Sample screenshots
Select the image to zoom in.