aspire

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Aspire Orchestration

Aspire 编排

Overview

概述

Code-first orchestration for polyglot distributed apps. AppHost defines topology,
aspire run
orchestrates locally,
azd deploy
deploys to Azure.
Auto-activates on keywords: aspire, microservices, distributed app, service discovery, orchestration
面向多语言分布式应用的代码优先编排工具。通过AppHost定义拓扑结构,使用
aspire run
在本地执行编排,
azd deploy
部署至Azure。
自动触发关键词:aspire、微服务、分布式应用、服务发现、编排

Quick Start

快速开始

bash
undefined
bash
undefined

Install .NET 8+ and Aspire workload

Install .NET 8+ and Aspire workload

dotnet workload update dotnet workload install aspire
dotnet workload update dotnet workload install aspire

Create AppHost (orchestrates services in ANY language)

Create AppHost (orchestrates services in ANY language)

dotnet new aspire-apphost -n MyApp
dotnet new aspire-apphost -n MyApp

Basic AppHost - orchestrate Python, Node.js, .NET services

Basic AppHost - orchestrate Python, Node.js, .NET services

var builder = DistributedApplication.CreateBuilder(args); var redis = builder.AddRedis("cache");
// Python service var pythonApi = builder.AddExecutable("python-api", "python", ".").WithArgs("app.py").WithReference(redis);
// Node.js service var nodeApi = builder.AddExecutable("node-api", "node", ".").WithArgs("server.js").WithReference(redis);
// .NET service var dotnetApi = builder.AddProject<Projects.Api>("api").WithReference(redis);
builder.Build().Run();
var builder = DistributedApplication.CreateBuilder(args); var redis = builder.AddRedis("cache");
// Python service var pythonApi = builder.AddExecutable("python-api", "python", ".").WithArgs("app.py").WithReference(redis);
// Node.js service var nodeApi = builder.AddExecutable("node-api", "node", ".").WithArgs("server.js").WithReference(redis);
// .NET service var dotnetApi = builder.AddProject<Projects.Api>("api").WithReference(redis);
builder.Build().Run();

Run (orchestrates ALL languages)

Run (orchestrates ALL languages)

aspire run # Dashboard opens at http://localhost:15888
undefined
aspire run # Dashboard opens at http://localhost:15888
undefined

Core Workflows

核心工作流

Project Setup

项目搭建

bash
dotnet new aspire-apphost -n MyApp
dotnet new webapi -n MyApp.Api
dotnet add MyApp.AppHost reference MyApp.Api
AppHost: Resource topology in
Program.cs
ServiceDefaults: Shared config (logging, telemetry, resilience) Services: Your apps (APIs, workers, web apps)
bash
dotnet new aspire-apphost -n MyApp
dotnet new webapi -n MyApp.Api
dotnet add MyApp.AppHost reference MyApp.Api
AppHost:在
Program.cs
中定义资源拓扑 ServiceDefaults:共享配置(日志、遥测、弹性) Services:你的应用程序(API、工作进程、Web应用)

Dependency Configuration

依赖配置

csharp
// PostgreSQL
var postgres = builder.AddPostgres("db").AddDatabase("mydb");
var api = builder.AddProject<Projects.Api>("api").WithReference(postgres);

// Redis
var redis = builder.AddRedis("cache").WithRedisCommander();
var api = builder.AddProject<Projects.Api>("api").WithReference(redis);

// RabbitMQ
var rabbitmq = builder.AddRabbitMQ("messaging");
var worker = builder.AddProject<Projects.Worker>("worker").WithReference(rabbitmq);

// Access in code (connection strings auto-injected)
builder.Services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = builder.Configuration.GetConnectionString("cache");
});
csharp
// PostgreSQL
var postgres = builder.AddPostgres("db").AddDatabase("mydb");
var api = builder.AddProject<Projects.Api>("api").WithReference(postgres);

// Redis
var redis = builder.AddRedis("cache").WithRedisCommander();
var api = builder.AddProject<Projects.Api>("api").WithReference(redis);

// RabbitMQ
var rabbitmq = builder.AddRabbitMQ("messaging");
var worker = builder.AddProject<Projects.Worker>("worker").WithReference(rabbitmq);

// Access in code (connection strings auto-injected)
builder.Services.AddStackExchangeRedisCache(options =>
{
    options.Configuration = builder.Configuration.GetConnectionString("cache");
});

Local Development

本地开发

bash
aspire run  # Starts all services
Dashboard (localhost:15888): Resources, logs, traces, metrics Hot Reload: Auto-rebuild on code changes Debugging: Attach to individual services via IDE
bash
aspire run  # Starts all services
仪表板(localhost:15888):资源、日志、追踪、指标 热重载:代码变更时自动重建 调试:通过IDE附加到单个服务

Cloud Deployment

云端部署

bash
azd init  # Initialize Azure Developer CLI
azd up    # Deploy (generates Bicep → Azure Container Apps)
azd deploy -e production  # Deploy to specific environment
Generates: Bicep → Container Apps + networking + managed identities
bash
azd init  # Initialize Azure Developer CLI
azd up    # Deploy (generates Bicep → Azure Container Apps)
azd deploy -e production  # Deploy to specific environment
生成内容: Bicep → 容器应用 + 网络 + 托管标识

Navigation Guide

导航指南

When setting up projects:
  • examples.md lines 8-31 → Minimal project
  • examples.md lines 518-608 → Add Python service
  • examples.md lines 610-669 → Add Node.js service
  • examples.md lines 671-768 → Add Go service
When adding infrastructure:
  • reference.md lines 47-148 → Database APIs (PostgreSQL, Redis, MongoDB)
  • examples.md lines 39-95 → Redis integration
  • examples.md lines 102-176 → PostgreSQL integration
When deploying:
  • commands.md lines 215-288 → Full azd workflow
  • examples.md lines 387-515 → Azure deployment walkthrough
  • patterns.md lines 5-42 → HA configuration
When debugging:
  • troubleshooting.md lines 5-112 → Orchestration failures
  • troubleshooting.md lines 291-397 → Connection issues
  • commands.md lines 131-179 → Debug commands
搭建项目时:
  • examples.md 第8-31行 → 最小化项目
  • examples.md 第518-608行 → 添加Python服务
  • examples.md 第610-669行 → 添加Node.js服务
  • examples.md 第671-768行 → 添加Go服务
添加基础设施时:
  • reference.md 第47-148行 → 数据库API(PostgreSQL、Redis、MongoDB)
  • examples.md 第39-95行 → Redis集成
  • examples.md 第102-176行 → PostgreSQL集成
部署时:
  • commands.md 第215-288行 → 完整azd工作流
  • examples.md 第387-515行 → Azure部署演练
  • patterns.md 第5-42行 → 高可用配置
调试时:
  • troubleshooting.md 第5-112行 → 编排失败问题
  • troubleshooting.md 第291-397行 → 连接问题
  • commands.md 第131-179行 → 调试命令

Quick Reference

快速参考

Essential commands: See commands.md for complete reference
Polyglot patterns:
csharp
builder.AddProject<Projects.Api>("api");  // .NET
builder.AddExecutable("python-api", "python", ".").WithArgs("app.py");  // Python
builder.AddExecutable("node-api", "node", ".").WithArgs("server.js");  // Node.js
builder.AddExecutable("go-svc", "go", ".").WithArgs("run", "main.go");  // Go
Service discovery:
.WithReference(redis)
in AppHost →
GetConnectionString("cache")
in service
核心命令: 查看commands.md获取完整参考
多语言模式:
csharp
builder.AddProject<Projects.Api>("api");  // .NET
builder.AddExecutable("python-api", "python", ".").WithArgs("app.py");  // Python
builder.AddExecutable("node-api", "node", ".").WithArgs("server.js");  // Node.js
builder.AddExecutable("go-svc", "go", ".").WithArgs("run", "main.go");  // Go
服务发现: 在AppHost中使用
.WithReference(redis)
→ 在服务中使用
GetConnectionString("cache")

Integration with Amplihack

与Amplihack的集成

Command:
/ultrathink "Setup Aspire for microservices"
  • prompt-writer clarifies requirements → architect uses reference.md for API design
  • builder uses examples.md for implementation → reviewer checks patterns.md for best practices
  • tester uses troubleshooting.md for validation
Agent-Skill mapping:
  • architect → reference.md (API design)
  • builder → examples.md (implementation)
  • reviewer → patterns.md (best practices)
  • tester → troubleshooting.md (validation)
  • all agents → commands.md (CLI operations)
命令
/ultrathink "Setup Aspire for microservices"
  • 提示编写者明确需求 → 架构师使用reference.md进行API设计
  • 构建者使用examples.md进行实现 → 审核者使用patterns.md检查最佳实践
  • 测试者使用troubleshooting.md进行验证
Agent-技能映射:
  • 架构师 → reference.md(API设计)
  • 构建者 → examples.md(实现)
  • 审核者 → patterns.md(最佳实践)
  • 测试者 → troubleshooting.md(验证)
  • 所有Agent → commands.md(CLI操作)