Skip to content

Add overload to WithEnvironment for ReferenceExpression#3996

Merged
davidfowl merged 1 commit intomicrosoft:mainfrom
andi0b:withenvironment-referenceexpression
May 1, 2024
Merged

Add overload to WithEnvironment for ReferenceExpression#3996
davidfowl merged 1 commit intomicrosoft:mainfrom
andi0b:withenvironment-referenceexpression

Conversation

@andi0b
Copy link
Copy Markdown
Contributor

@andi0b andi0b commented Apr 28, 2024

This adds an overload to resource.WithEnvironment to accept RefrerenceExpression. With this API change it's more obvious how to pass a ReferenceExpresson,

This was suggested by @davidfowl in #2111 (comment)

Example before this PR:

builder.AddNpmApp(...)
    .WithEnvironment(context => context.EnvironmentVariables["DB_CONNECTION_URL"] = db.Resource.GetConnectionUrl());

after:

builder.AddNpmApp(...)
    .WithEnvironment("DB_CONNECTION_URL", db.Resource.GetConnectionUrl());

In this example GetConnectionUrl() is an extension method that builds a custom connection URL and returns ReferenceExpression, see full example: #2111 (comment)

Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Apr 28, 2024
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Apr 28, 2024
@andi0b
Copy link
Copy Markdown
Contributor Author

andi0b commented Apr 28, 2024

@dotnet-policy-service agree

@davidfowl davidfowl changed the title Add overload to WithEnvironment for RefereceExpression Add overload to WithEnvironment for ReferenceExpression Apr 28, 2024
@davidfowl davidfowl merged commit 2b9e4de into microsoft:main May 1, 2024
@davidfowl
Copy link
Copy Markdown
Contributor

/backport to release/8.0

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2024

Started backporting to release/8.0: https://github.com/dotnet/aspire/actions/runs/8905408380

@davidfowl
Copy link
Copy Markdown
Contributor

Thanks!

@github-actions github-actions Bot locked and limited conversation to collaborators Jun 1, 2024
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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants