Skip to content

Allow CosmosDB connection strings to work with Database and Container keys#7422

Merged
davidfowl merged 2 commits intomicrosoft:mainfrom
eerhardt:CosmosConnectionStrings
Feb 6, 2025
Merged

Allow CosmosDB connection strings to work with Database and Container keys#7422
davidfowl merged 2 commits intomicrosoft:mainfrom
eerhardt:CosmosConnectionStrings

Conversation

@eerhardt
Copy link
Copy Markdown
Member

@eerhardt eerhardt commented Feb 5, 2025

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

  • Is this feature complete?
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
  • Did you add public API?
    • No
  • Does the change make any security assumptions or guarantees?
    • No
  • Does the change require an update in our Aspire docs?
    • No

… 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
Comment thread src/Shared/Cosmos/CosmosUtils.cs Outdated
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
return new CosmosConnectionInfo(accountEndpoint, null);
}

var connectionBuilder = new DbConnectionStringBuilder()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future: If we're going all in on connection strings, it might be worth shipping a public API that uses DbConnectionStringBuilder internally.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. #7427

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: CosmosConnectionInfo and CosmosConnectionInfo.ParseConnectionString

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Sorry for the confusion, I was using the existing internal names above. Not what I would use for public API.

@davidfowl davidfowl merged commit 98f0d8d into microsoft:main Feb 6, 2025
@eerhardt eerhardt deleted the CosmosConnectionStrings branch February 6, 2025 15:18
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 9, 2025
@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Mar 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants