Loading...
Loading...
Configures .NET Aspire 13.x orchestration, service discovery, and telemetry. Use when: Adding services to AppHost, configuring service defaults, setting up health checks, troubleshooting service discovery, or using Aspire CLI commands.
npx skill4agent add stuartf303/sorcha aspiresrc/Apps/Sorcha.AppHost/AppHost.csAddServiceDefaults()| Component | Version | Notes |
|---|---|---|
| Aspire.AppHost.Sdk | 13.0.0 | SDK in |
| Aspire.Hosting.* | 13.1.0 | AppHost hosting packages |
| Aspire.StackExchange.Redis | 13.1.0 | Service-level Redis integration |
| Aspire.Hosting.Testing | 13.1.0 | Integration/E2E test infrastructure |
| Aspire Dashboard | 9.0.0 | Docker image (separate versioning) |
src/Apps/Sorcha.AppHost/Sorcha.AppHost.csprojsrc/Common/Sorcha.ServiceDefaults/Extensions.csAspire.StackExchange.RedisAspire.Hosting.Testing// In AppHost.cs - Add project with resource references
var myService = builder.AddProject<Projects.Sorcha_MyService>("my-service")
.WithReference(redis) // Service discovery
.WithReference(walletDb) // Database connection
.WithEnvironment("JwtSettings__SigningKey", jwtSigningKey); // Shared config// Control the environment variable prefix for a resource reference
var myService = builder.AddProject<Projects.Sorcha_MyService>("my-service")
.WithReference(postgres.AddDatabase("mydb"), "primary-db"); // ConnectionStrings__primary-db// In Program.cs - Every service starts with this
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults(); // OpenTelemetry, health checks, discovery
builder.AddRedisOutputCache("redis"); // Reference by resource name
builder.AddRedisDistributedCache("redis");
var app = builder.Build();
app.MapDefaultEndpoints(); // /health and /alive| Concept | Usage | Example |
|---|---|---|
| Resource Name | Identifier for service discovery | |
| WithReference | Injects connection string/URL | |
| Named Reference | Custom env var prefix (v13+) | |
| WithEnvironment | Pass config to service | |
| WithExternalHttpEndpoints | Expose outside Aspire network | |
| AddServiceDefaults | Shared Aspire configuration | |
| Connection Properties | Access individual fields (v13+) | |
| WithHttpsCertificate | TLS termination (v13.1+) | |
| ContainerRegistryResource | Registry config (v13.1+ exp.) | |
<Project Sdk="Aspire.AppHost.Sdk/13.0.0">HostNamePortJdbcConnectionStringWithReference(resource, "customName")PublishWithContainerFiles()aspire doWithHttpsCertificate()ContainerRegistryResourceAddAzureRedisEnterprise()| Old API | New API | Notes |
|---|---|---|
| | Removed in v13 |
| Refactored | Different parameter ordering |
| | Package renamed |
| | OpenAI/GitHub models |
| | Milvus/MongoDB/MySQL/Oracle |
Dual-SDK | Single SDK | Optional migration |
AppHost.cs orchestrates:
postgres ──┬── tenant-db ───── tenant-service
└── wallet-db ───── wallet-service
mongodb ───── register-db ──── register-service
redis ────── (shared by all services)
tenant-service ──── (JWT issuer, auth provider)
blueprint-service ─── (workflow engine)
validator-service ──── wallet-service, register-service, peer-service, blueprint-service
api-gateway ──── (routes to all services, external HTTP)
ui-web ──── api-gateway (Blazor WASM frontend)// PostgreSQL with multiple databases
var postgres = builder.AddPostgres("postgres").WithPgAdmin();
var tenantDb = postgres.AddDatabase("tenant-db", "sorcha_tenant");
var walletDb = postgres.AddDatabase("wallet-db", "sorcha_wallet");
// MongoDB for document storage
var mongodb = builder.AddMongoDB("mongodb").WithMongoExpress();
var registerDb = mongodb.AddDatabase("register-db", "sorcha_register");
// Redis for caching
var redis = builder.AddRedis("redis").WithRedisCommander();// Service references other services for discovery
var validatorService = builder.AddProject<Projects.Sorcha_Validator_Service>("validator-service")
.WithReference(redis)
.WithReference(walletService)
.WithReference(registerService)
.WithReference(peerService)
.WithReference(blueprintService);// ServiceDefaults provides these automatically
app.MapHealthChecks("/health"); // Readiness - all checks
app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live") // Liveness - tagged checks only
});// Configure HTTPS certificates on containers
var redis = builder.AddRedis("redis")
.WithHttpsCertificate(cert);
// YARP with TLS
var gateway = builder.AddProject<Projects.Sorcha_ApiGateway>("api-gateway")
.WithHttpsCertificate();Fetch latest .NET Aspire documentation with Context7.
mcp__context7__resolve-library-id/websites/mcp__context7__query-docs/dotnet/docs-aspire