Repository navigation
Add IServiceProvider support to Cosmos DB extensions - #19349
Sébastien Ros (sebastienros) merged 4 commits into
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19349Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19349" |
There was a problem hiding this comment.
Pull request overview
Adds DI-aware Cosmos DB client option callbacks, enabling service resolution during client creation.
Changes:
- Adds
IServiceProvidercallback overloads. - Defers client option configuration until resolution.
- Adds documentation and tests for legacy, DI-aware, and concurrent scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
AspireMicrosoftAzureCosmosExtensions.cs |
Adds overloads and centralizes registration. |
CosmosDatabaseBuilder.cs |
Shares clients through keyed DI. |
README.md |
Documents DI-aware configuration. |
AspireMicrosoftAzureCosmosExtensionsTests.cs |
Tests callbacks and concurrency. |
MicrosoftAzureCosmosPublicApiTests.cs |
Tests overload validation. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Tagging Debdatta Kunda (@kundadebdatta) too. This LGTM from the Cosmos DB side of things. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/Components/Aspire.Microsoft.Azure.Cosmos/AspireMicrosoftAzureCosmosExtensions.cs:291
- Client creation is now deferred to singleton resolution, but all six public registration methods still document
InvalidOperationExceptionas being thrown by the registration call when connection information is missing. The methods now return successfully and that failure (as well as exceptions fromconfigureClientOptions) occurs when the registered service is first resolved, so the IntelliSense contract is inaccurate. Update each overload pair's XML documentation to describe the deferred callback/client creation and resolution-time failure.
return (settings, serviceProvider =>
{
var clientOptions = new CosmosClientOptions();
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
3e79c9a to
e79c47b
Compare
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Restore shipped configuration overloads while adding provider-aware options callbacks, retaining registration-time behavior for existing consumers. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 900b109d-3fff-4396-abba-b9e14bb5b877
Breaking API changes are permitted on main for this major release; retain the intended provider-aware Cosmos callback API. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 900b109d-3fff-4396-abba-b9e14bb5b877
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 900b109d-3fff-4396-abba-b9e14bb5b877
9bdf349
into
microsoft:main
Description
Add IServiceProvider support to Cosmos DB extensions - co-authored with GPT 5.6-Sol
The benefit would be using the DI container to resolve
RequestHandlerinstances that may require container services to instantiate as part of callingclientOptions.CustomHanndlers.Add(...);This is a breaking change for 17.0 to change
Action<CosmosClientOptions>toAction<IServiceProvider, CosmosClientOptions>for the Cosmos DB integration package.Action<CosmosClientOptions>? configureClientOptionswould throw upon registration. Now, they will only throw upon client resolution from the DI container.Partially addresses #667
Checklist
<remarks />and<code />elements on your triple slash comments?Testing
Built local packages and pulled them into a real Microsoft internal project. Built and executed, with a breakpoint to watch the
clientOptionscallback get called. Deleted my internal copy ofAspireMicrosoftAzureCosmosExtensionsto call the package version added by this PR.Old overloads still work:

New overloads work as expected:
