What is a Resource?
A resource is any component in your application that implements theIResource interface. Every resource has:
- A name - Used for service discovery and identification
- Annotations - Metadata that describes configuration, endpoints, and behavior
- A type - Determines how the resource is deployed and managed
Resource Types
.NET Aspire supports three primary compute resource types:Projects
.NET applications running in your solution
Containers
Docker containers for databases, caches, etc.
Executables
Any command-line program or process
Project Resources
Project resources represent .NET projects in your solution. They’re automatically compiled, run, and monitored.Adding a Project
- From Solution
- From Path
Reference a project that’s already in your solution:The
Projects.Api type is auto-generated when you add a project reference to your AppHost project.Project Configuration
Aspire automatically reads
launchSettings.json to configure endpoints. You can specify which profile to use:var api = builder.AddProject<Projects.Api>("api", options =>
{
options.ExcludeLaunchProfile = true;
});
Project endpoints are automatically discovered from Kestrel configuration. If your project’s
appsettings.json contains:{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
},
"Https": {
"Url": "https://localhost:5001"
}
}
}
}
Container Resources
Container resources run Docker or Podman containers. They’re perfect for databases, caches, message queues, and third-party services.Adding a Container
Common Container Configuration
Advanced Container Options
Custom Entrypoint
Custom Entrypoint
Override the container’s entrypoint:
Container Lifetime
Container Lifetime
Control when containers are stopped:Options:
Persistent- Container keeps running after AppHost stopsSession- Container stops when AppHost stops (default)
Network Aliases
Network Aliases
Add custom DNS names for container-to-container communication:
Integration Resources
.NET Aspire provides pre-built integrations for common containers:Executable Resources
Executable resources run any command-line program. They’re useful for:- Node.js, Python, or other non-.NET applications
- Build tools and scripts
- Custom services that don’t run in containers
Adding an Executable
- name - Resource identifier
- command - The executable to run (must be in PATH or use full path)
- workingDirectory - Where to run the command
- args - Command-line arguments
Executable Configuration
Node.js, NPM, and Yarn
Aspire provides specialized methods for JavaScript applications:- Node.js
- NPM
- Yarn
Resource Builder Pattern
All resource methods return anIResourceBuilder<T>, enabling a fluent configuration syntax:
- Configure the resource
- Add annotations
- Wire dependencies
- Access the underlying resource
Working with Resources
Get a Resource Reference
The builder returns a typed reference you can use later:Resource Names
Every resource must have a unique name (case-insensitive):- Service discovery
- Dashboard display
- Logging and diagnostics
- Generated connection string keys
Next Steps
Wire Dependencies
Connect resources using WithReference
Configuration
Learn about configuration management
Environment Variables
Pass configuration to resources
Hosting Integrations
Explore pre-built integrations