Skip to content

Enhance external parameters article with 9.2 AddConnectionString capabilities #2710

@davidfowl

Description

@davidfowl

We just merged dotnet/aspire#7826 into 9.2 which adds an overload of AddConnectionString that supports passing in a reference expression.

There are a few key things this enables:

  1. Creating adhoc connection strings made from various parameters:

    var openAiKey = builder.AddParameter("openaikey", secret: true);
    var oaiCs = builder.AddConnectionString("llm", ReferenceExpression.Create($"Endpoint=https://api.openai.com/v1;Key={openAiKey}"));
  2. Appending to existing connection strings.

     var builder = DistributedApplication.CreateBuilder(args);
    
     var postgres = builder
         .AddPostgres("postgres")
    
     var database = postgres.AddDatabase("db");
    
     var cs = builder.AddConnectionString("database", ReferenceExpression.Create($"{database};Include Error Details=true"));
    
     var backend = builder
         .AddProject<Projects.Backend>("backend")
         .WithReference(cs)
         .WaitFor(cs);
    
     builder.Build().Run();

    Waiting for a connection string will wait for the database implicitly.

This article should be updated to show the new scenarios.


Associated WorkItem - 427446

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions