Allow CosmosDB connection strings to work with Database and Container keys#7422
Merged
davidfowl merged 2 commits intomicrosoft:mainfrom Feb 6, 2025
Merged
Conversation
… keys With microsoft#7408, Cosmos Database and Containers are Aspire Resources now, which means they can be referenced via WithReference. In the future, the Cosmos Host integration will append these values to the connection string. This will allow the database and container names to be specified outside of the application. (Today they are hard-coded in both, or specified separately in config.) We can also add new client APIs to register a Database or Container object in DI. This is a stop-gap to support these values in .NET Aspire 9.1 client integration so it doesn't break applications when we start adding these values in the future. Contributes to microsoft#7407
eerhardt
commented
Feb 5, 2025
3 tasks
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
davidfowl
reviewed
Feb 6, 2025
| return new CosmosConnectionInfo(accountEndpoint, null); | ||
| } | ||
|
|
||
| var connectionBuilder = new DbConnectionStringBuilder() |
Contributor
There was a problem hiding this comment.
future: If we're going all in on connection strings, it might be worth shipping a public API that uses DbConnectionStringBuilder internally.
Member
Author
There was a problem hiding this comment.
future: If we're going all in on connection strings, it might be worth shipping a public API that uses DbConnectionStringBuilder internally.
Yes, I can imagine shipping something like CosmosConnectionInfo and CosmosUtils.ParseConnectionString publicly.
Contributor
There was a problem hiding this comment.
nit: CosmosConnectionInfo and CosmosConnectionInfo.ParseConnectionString
Member
Author
There was a problem hiding this comment.
Agreed. Sorry for the confusion, I was using the existing internal names above. Not what I would use for public API.
davidfowl
approved these changes
Feb 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With #7408, Cosmos Database and Containers are Aspire Resources now, which means they can be referenced via WithReference.
In the future, the Cosmos Host integration will append these values to the connection string. This will allow the database and container names to be specified outside of the application. (Today they are hard-coded in both, or specified separately in config.) We can also add new client APIs to register a Database or Container object in DI.
This is a stop-gap to support these values in .NET Aspire 9.1 client integration so it doesn't break applications when we start adding these values in the future.
Contributes to #7407
Checklist