Skip to content

Conversation

@eerhardt
Copy link
Member

Description

When setting environment variables on a resource, it is useful to get the resource so you can grab annotations off of it to use in the environment settings.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?
    • No

@eerhardt eerhardt requested review from Copilot and davidfowl March 25, 2025 18:39
@eerhardt eerhardt requested a review from mitchdenny as a code owner March 25, 2025 18:39
@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Mar 25, 2025
Copy link
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

This pull request adds support for passing the resource into environment callback contexts so that environment variable callbacks can access resource annotations. It updates the constructors for EnvironmentCallbackContext across multiple areas and adds tests to verify that the resource is available.

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
playground/AzureContainerApps/AzureContainerApps.AppHost/Program.cs Adds a new environment callback that uses the resource to retrieve an annotation.
tests/Aspire.Hosting.Tests/ResourceExtensionsTests.cs Inserts an assertion that ensures the resource is set in the environment callback.
tests/Aspire.Hosting.Tests/WithEnvironmentTests.cs Updates callbacks to assert that the resource is not null.
tests/Aspire.Hosting.Tests/ExpressionResolverTests.cs Adds a check for a non-null resource in an environment variable callback.
src/Aspire.Hosting/ApplicationModel/EnvironmentCallbackContext.cs Introduces a new constructor and exposes the Resource property with proper null-checking.
src/Aspire.Hosting.Azure/AzureResourcePreparer.cs Updates the EnvironmentCallbackContext instantiation to include the resource.
src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs Updates the instantiation to pass the resource into the EnvironmentCallbackContext.
src/Aspire.Hosting.Kubernetes/KubernetesResourceContext.cs Passes the resource to the EnvironmentCallbackContext in environment processing.
src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppsInfrastructure.cs Updates environment callback processing to use the new constructor with resource.
src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs Changes the instantiation of EnvironmentCallbackContext to correctly include the resource and the environment variables dictionary.
Files not reviewed (2)
  • playground/AzureContainerApps/AzureContainerApps.AppHost/api.module.bicep: Language not supported
  • playground/AzureContainerApps/AzureContainerApps.AppHost/aspire-manifest.json: Language not supported

@davidfowl davidfowl merged commit 7f20beb into dotnet:main Mar 26, 2025
164 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants