Skip to content

feat(cosmos): add configuration support for grain storage - #10326

Merged
ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:fix/cosmos-doc-id-provider
Aug 4, 2026
Merged

ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:fix/cosmos-doc-id-provider

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Aug 2, 2026

Copy link
Copy Markdown
Member

Follow-up to #8699.

Adds IConfiguration support for Cosmos grain storage and addresses the document ID provider configuration feedback.

  • Registers AzureCosmosDB as a GrainStorage provider.
  • Binds CosmosGrainStorageOptions from the provider configuration section.
  • Supports ServiceKey, ConnectionName, and ConnectionString for the Cosmos client.
  • Supports DocumentIdProviderKey, resolving an application-registered keyed IDocumentIdProvider through dependency injection and aliasing it to the storage provider name.
  • Keeps service selection out of CosmosGrainStorageOptions and avoids reflection/type-name activation.

Tests cover keyed provider resolution, constructor dependency injection, and named options binding on net8.0 and net10.0.

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e82f060d-d09b-42f9-8b0f-34da38b386fa

Copilot AI left a comment

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.

Pull request overview

Adds configuration-based provider wiring for Cosmos grain storage in Orleans, enabling options binding from IConfiguration and DI-based selection of a keyed IDocumentIdProvider without reflection/type-name activation.

Changes:

  • Introduces CosmosGrainStorageProviderBuilder registered as the AzureCosmosDB GrainStorage provider, binding CosmosGrainStorageOptions from configuration and supporting ServiceKey/ConnectionName/ConnectionString Cosmos client selection.
  • Adds support for DocumentIdProviderKey to alias an application-registered keyed IDocumentIdProvider to the storage provider’s name.
  • Adds/extends tests to validate keyed provider resolution, DI constructor injection, and named options binding.
Show a summary per file
File Description
test/Extensions/Orleans.Cosmos.Tests/CosmosHostingExtensionsTests.cs Adds coverage for config-driven DocumentIdProviderKey resolution and named options binding.
src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorageProviderBuilder.cs New provider builder registering AzureCosmosDB grain storage and binding/deriving options from IConfiguration.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

@ReubenBond ReubenBond changed the title Add configuration support for Cosmos grain storage feat(cosmos): add configuration support for grain storage Aug 3, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: cc82c70d-1c36-4b98-92d4-d9e0c2bce556
Copilot AI review requested due to automatic review settings August 4, 2026 21:15

Copilot AI left a comment

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.

Copilot's findings

Suppressed comments (1)

src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorageProviderBuilder.cs:23

  • If DocumentIdProviderKey is set to the same value as the storage provider name (name), this registration becomes self-referential and will trigger a circular dependency when resolving the keyed IDocumentIdProvider (keyed by name). Consider failing fast with a clear error (or skipping the aliasing) when the keys are equal.
        var documentIdProviderKey = configurationSection["DocumentIdProviderKey"];
        if (!string.IsNullOrEmpty(documentIdProviderKey))
        {
            builder.Services.AddKeyedSingleton<IDocumentIdProvider>(
                name,
                (services, _) => services.GetRequiredKeyedService<IDocumentIdProvider>(documentIdProviderKey));
        }
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new

@ReubenBond
ReubenBond merged commit 114eae1 into dotnet:main Aug 4, 2026
66 of 67 checks passed
@ReubenBond
ReubenBond deleted the fix/cosmos-doc-id-provider branch August 4, 2026 21:36
This was referenced Aug 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants