Skip to content

Adds a new section that describes WithReference and equivalent methods in the "What are Aspire Integrations?" article#795

Open
alistairmatthews wants to merge 2 commits intomicrosoft:mainfrom
alistairmatthews:move-withreference-discussion
Open

Adds a new section that describes WithReference and equivalent methods in the "What are Aspire Integrations?" article#795
alistairmatthews wants to merge 2 commits intomicrosoft:mainfrom
alistairmatthews:move-withreference-discussion

Conversation

@alistairmatthews
Copy link
Copy Markdown
Contributor

This PR adds a discussion of WithReference() and equivalent methods for other AppHost languages, to the What are Aspire integrations? article. This approach will reduce the amount of language-specific examples we have to include in the connection article for each integration.

Fixes: #794

Copilot AI review requested due to automatic review settings May 1, 2026 14:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new documentation section to the “What are Aspire integrations?” overview page explaining how WithReference() (and language equivalents) wire AppHost resources to consuming projects via injected environment variables, helping reduce repetition across individual integration connection articles.

Changes:

  • Introduces a new “Wiring resources to consuming projects with references” section describing WithReference() semantics.
  • Adds AppHost-language pivoted examples (C# / TypeScript) and a follow-up section showing how injected environment variables can be consumed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/frontend/src/content/docs/integrations/overview.mdx Outdated
Comment thread src/frontend/src/content/docs/integrations/overview.mdx Outdated
Copy link
Copy Markdown
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start.

Comment on lines +52 to +59
<PivotSelector
title="Select your AppHost language"
key="aspire-lang"
options={[
{ id: 'csharp', title: 'C#' },
{ id: 'typescript', title: 'TypeScript' },
]}
/>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tabs here, no need for the pivot. You're already using tabs below.


## Wiring resources to consuming projects with references

Once you've created resources, such as databases or messaging systems, by setting up hosting integrations in the AppHost, you can pass those resources to consuming projects, such as APIs or web apps, by calling the `WithReference` method, or its equivalent for your preferred language. These methods express an explicit dependency between a resource and a consuming project. When Aspire starts, it injects connection information as environment variables into the consuming project so it can locate and connect to that resource.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Once you've created resources, such as databases or messaging systems, by setting up hosting integrations in the AppHost, you can pass those resources to consuming projects, such as APIs or web apps, by calling the `WithReference` method, or its equivalent for your preferred language. These methods express an explicit dependency between a resource and a consuming project. When Aspire starts, it injects connection information as environment variables into the consuming project so it can locate and connect to that resource.
Once you've created resources, such as databases or messaging systems, by setting up hosting integrations in the AppHost, you can pass those resources to consuming projects, such as APIs or web apps, by calling the "with reference" APIs. These methods express an explicit dependency between a resource and a consuming project. When Aspire starts, it injects connection information as environment variables into the consuming project so it can locate and connect to that resource.

The environment variables Aspire injects depend on the type of resource being referenced. For example:

- **Connection string resources**: Aspire sets a `ConnectionStrings__{name}` environment variable, where `{name}` matches the resource name. For example, `.WithReference(cache)` on a resource named `"cache"`, that is available on port 6379, injects `ConnectionStrings__cache=localhost:6379`.
- **Service endpoint resources**: Aspire sets `services__{name}__{scheme}__{index}` variables used for service discovery. For example, referencing a project named `api`, that is available on port 7001, injects `services__api__https__0=https://localhost:7001`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the simple env var names instead of the legacy names.


The environment variables Aspire injects depend on the type of resource being referenced. For example:

- **Connection string resources**: Aspire sets a `ConnectionStrings__{name}` environment variable, where `{name}` matches the resource name. For example, `.WithReference(cache)` on a resource named `"cache"`, that is available on port 6379, injects `ConnectionStrings__cache=localhost:6379`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid a callout to an explicit .NET API, simply say something like "when one resource chains a call to reference another resource". Leave the code parts for the tabs.


Any application can read these environment variables to connect to its dependencies. A Python, Node.js, or other app can read variables directly, without any Aspire-specific libraries.

If your consuming project is written in .NET C#, you have an additional option: [**Aspire client integrations**](#client-integrations):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to avoid saying ".NET", "C#" is much better branding. Also, I think we should just let the tabs speak for themselves. Instead of calling out C# here - instead let the reader select C# if they want those details. In other words, please just fold this into the C# tab, let the reader know they can manually use Environment.GetEnvironmentVariable or the IConfiguration APIs, or preferably use the official client integrations.

Suggested change
If your consuming project is written in .NET C#, you have an additional option: [**Aspire client integrations**](#client-integrations):
If your consuming project is written in C#, you have an additional option: [**Aspire client integrations**](#client-integrations):


Once you've created resources, such as databases or messaging systems, by setting up hosting integrations in the AppHost, you can pass those resources to consuming projects, such as APIs or web apps, by calling the `WithReference` method, or its equivalent for your preferred language. These methods express an explicit dependency between a resource and a consuming project. When Aspire starts, it injects connection information as environment variables into the consuming project so it can locate and connect to that resource.

<PivotSelector
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have a generic mermaid diagram here or nearby, the is similar to what was added in the Postgres get started, that shows two "resources" modeled in the AppHost and helps visualize how hosting and client integrations relate from that perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a discussion of WithReference and equivalent methods to the What are Aspire integrations? article

3 participants