C#C
C#β€’6mo ago
JA$PER

Aspire custom connection string env variable

So i just started using aspire πŸš€
In my project i want to spin up a mongodb database, but my project uses a non default connection strings environment variable. The connection string should be in the variable
Database__ConnectionString
, but i can only get it to be the default
ConnectionString__X
. Is there any way to "re-map" the default connectionstring varible to my custom one?

var mongodb = builder.AddMongoDB("mongodb", 27017)
    .WithMongoExpress(containerName: "express")
    .AddDatabase("database", "Development")
    ;

var api = builder.AddProject<Projects.BumpBuddy_Api>("api")
    .WithHttpHealthCheck("/health")
    .WithReference(mongodb);



Edit:
Went to the aspire source code and got my answer

I added this to my api project:
.WithEnvironment("Database__ConnectionString", mongodb.Resource.ConnectionStringExpression)


mongodb.Resource.ConnectionStringExpression has the connectionstring.
Was this page helpful?