Skip to content

Commit c7a508c

Browse files
committed
feat: Add .NET Aspire orchestration guide and update related documentation and links.
1 parent dd769a8 commit c7a508c

6 files changed

Lines changed: 106 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ BookStore/
124124

125125
- **[Getting Started](docs/getting-started.md)** - Setup and first steps
126126
- **[Architecture Overview](docs/architecture.md)** - System design and patterns
127+
- **[Aspire Orchestration Guide](docs/aspire-guide.md)** - Service orchestration and local development
127128
- **[Aspire Deployment Guide](docs/aspire-deployment-guide.md)** - Deploy to Azure and Kubernetes
128129
- **[Production Scaling Guide](docs/production-scaling-guide.md)** - Scale applications and databases in production
129130
- **[Configuration Guide](docs/configuration-guide.md)** - Options pattern and validation

docs/architecture.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Example event flow:
236236
- **Wolverine 5.9.2** - Command/handler pattern and message bus
237237
- **Marten 8.17.0** - Event store and document DB
238238
- **PostgreSQL 16** - Database
239-
- **Aspire** - Orchestration and observability
239+
- **Aspire** - [Orchestration](aspire-guide.md) and observability
240240
- **Scalar 2.11.10** - API documentation
241241

242242
### Features
@@ -366,4 +366,5 @@ Example event flow:
366366
- **[Event Sourcing Guide](event-sourcing-guide.md)** - Event sourcing concepts and patterns
367367
- **[Marten Guide](marten-guide.md)** - Event sourcing implementation with Marten
368368
- **[Wolverine Guide](wolverine-guide.md)** - Command/handler pattern
369+
- **[Aspire Orchestration Guide](aspire-guide.md)** - Service orchestration details
369370
- **[Getting Started](getting-started.md)** - Setup and running the application

docs/aspire-deployment-guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ Use Aspire's local development experience:
526526
aspire run
527527
```
528528

529+
For a detailed look at the local orchestration configuration, see the [Aspire Orchestration Guide](aspire-guide.md).
530+
529531
This starts:
530532
- Aspire Dashboard
531533
- All services with hot reload

docs/aspire-guide.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# .NET Aspire Orchestration Guide
2+
3+
This guide explains how the BookStore solution uses **.NET Aspire** to orchestrate distributed services, manage local development resources, and simplify cloud-native application composition.
4+
5+
## Overview
6+
7+
The BookStore solution is built as a distributed system composed of:
8+
1. **API Service**: Event-sourced backend
9+
2. **Web Frontend**: Blazor interactive UI
10+
3. **Infrastructure**: PostgreSQL, Redis, and Azure Blob Storage
11+
12+
.NET Aspire serves as the glue that binds these components together, handling:
13+
- **Service Discovery**: Automatically injecting connection strings and service URLs.
14+
- **Resource Management**: Spinning up containers for databases and emulators during development.
15+
- **Observability**: Providing a unified dashboard for logs, traces, and metrics.
16+
17+
## AppHost: The Orchestrator
18+
19+
The `BookStore.AppHost` project is the entry point for the distributed application. It defines the architectural blueprint of the system in C#.
20+
21+
### Defined Resources
22+
23+
The AppHost defines the following resources in `Program.cs`:
24+
25+
#### 1. Databases & Storage
26+
- **PostgreSQL**: A containerized PostgreSQL instance.
27+
```csharp
28+
var postgres = builder.AddPostgres("postgres")
29+
.WithPgAdmin(); // Adds PgAdmin for database management
30+
var bookStoreDb = postgres.AddDatabase("bookstore");
31+
```
32+
- **Redis**: Distributed cache for the API and hybrid caching.
33+
```csharp
34+
var cache = builder.AddRedis("cache");
35+
```
36+
- **Azure Storage**: Uses the **Azurite** emulator for local development, providing Blob storage compatible with Azure.
37+
```csharp
38+
var storage = builder.AddAzureStorage("storage").RunAsEmulator();
39+
var blobs = storage.AddBlobs("blobs");
40+
```
41+
42+
#### 2. Services
43+
- **API Service** (`Projects.BookStore_ApiService`): The backend API. It declares dependencies on the database, blob storage, and cache.
44+
```csharp
45+
var apiService = builder.AddProject<Projects.BookStore_ApiService>("apiservice")
46+
.WithReference(bookStoreDb)
47+
.WithReference(blobs)
48+
.WithReference(cache)
49+
.WaitFor(postgres); // Startup dependency
50+
```
51+
- **Web Frontend** (`Projects.BookStore_Web`): The Blazor app. It depends on the API service to fetch data.
52+
```csharp
53+
builder.AddProject<Projects.BookStore_Web>("webfrontend")
54+
.WithReference(apiService)
55+
.WaitFor(apiService);
56+
```
57+
58+
### Service Discovery
59+
60+
Aspire automates connection management using the resource names defined in the AppHost.
61+
- **Databases**: The API service receives the connection string for "bookstore" automatically.
62+
- **HTTP Services**: The frontend receives the base URL for "apiservice" via the service discovery mechanism, allowing `HttpClient` to simply use `http://apiservice`.
63+
64+
## Service Defaults: Shared Concerns
65+
66+
The `BookStore.ServiceDefaults` project encapsulates cross-cutting concerns that every service needs. Both the API and Web projects reference this library and call `builder.AddServiceDefaults()` in their startup.
67+
68+
### Features
69+
- **OpenTelemetry**: Automatically configures logging, tracing, and metrics export to the Aspire Dashboard.
70+
- **Health Checks**: Adds standard `/health` and `/alive` endpoints.
71+
- **Service Discovery**: Configures `Microsoft.Extensions.ServiceDiscovery` to resolve Aspire resource names.
72+
73+
## Local Development Experience
74+
75+
To start the entire solution, simply run the AppHost project:
76+
77+
```bash
78+
aspire run
79+
# or
80+
dotnet run --project src/BookStore.AppHost/BookStore.AppHost.csproj
81+
```
82+
83+
### The Aspire Dashboard
84+
85+
When the application starts, the **Aspire Dashboard** launches automatically. It provides a centralized view of:
86+
- **Resources**: Status and endpoints of all running services and containers.
87+
- **Console Logs**: Real-time stdout/stderr from all projects.
88+
- **Structured Logs**: searchable table of log entries.
89+
- **Traces**: Distributed traces showing the flow of requests between frontend, API, and database.
90+
- **Metrics**: Real-time graphs for CPU, memory, and custom metrics.
91+
92+
## Production Considerations
93+
94+
While Aspire is excellent for local development, it also facilitates deployment. The AppHost can generate manifests for deployment to environments like **Azure Container Apps** or **Kubernetes**.
95+
96+
See the [Aspire Deployment Guide](aspire-deployment-guide.md) for detailed deployment instructions.

docs/getting-started.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ This will:
5858
- Start the Blazor web frontend
5959
- Open the Aspire dashboard in your browser
6060

61+
> [!TIP]
62+
> For a deep dive into how Aspire orchestrates the solution locally, see the [Aspire Orchestration Guide](aspire-guide.md).
63+
6164
## Accessing the Application
6265

6366
### Aspire Dashboard

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
href: correlation-causation-guide.md
2929
- name: API Conventions
3030
href: api-conventions-guide.md
31+
- name: Aspire Orchestration
32+
href: aspire-guide.md
3133
- name: Aspire Deployment
3234
href: aspire-deployment-guide.md
3335
- name: Production Scaling

0 commit comments

Comments
 (0)