From 708d547c997228d4ca588cab10873b574b1306a4 Mon Sep 17 00:00:00 2001 From: Michal Date: Fri, 27 Mar 2026 12:15:49 +0100 Subject: [PATCH 1/2] Add UseCosmosDbPersistence overload for DI-registered CosmosClient Adds a new overload of UseCosmosDbPersistence that resolves CosmosClient from the DI container instead of requiring a connection string or TokenCredential. This allows applications that already register CosmosClient in their service collection to wire up CosmosDB persistence without duplicating client configuration. --- .../ServiceCollectionExtensions.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs b/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs index e08d0445f..196c60d7f 100644 --- a/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs +++ b/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs @@ -106,5 +106,23 @@ public static WorkflowOptions UseCosmosDbPersistence( options.UsePersistence(sp => new CosmosDbPersistenceProvider(sp.GetService(), databaseId, sp.GetService(), cosmosDbStorageOptions)); return options; } + + public static WorkflowOptions UseCosmosDbPersistence( + this WorkflowOptions options, + string databaseId, + CosmosDbStorageOptions cosmosDbStorageOptions = null, + CosmosClientOptions clientOptions = null) + { + if (cosmosDbStorageOptions == null) + { + cosmosDbStorageOptions = new CosmosDbStorageOptions(); + } + + options.Services.AddSingleton(sp => new CosmosClientFactory(sp.GetService())); + options.Services.AddTransient(sp => new CosmosDbProvisioner(sp.GetService(), cosmosDbStorageOptions)); + options.Services.AddSingleton(sp => new WorkflowPurger(sp.GetService(), databaseId, cosmosDbStorageOptions)); + options.UsePersistence(sp => new CosmosDbPersistenceProvider(sp.GetService(), databaseId, sp.GetService(), cosmosDbStorageOptions)); + return options; + } } } From 129869df4bfd49ca132e7b6707491601c72e26ca Mon Sep 17 00:00:00 2001 From: Michal Date: Fri, 27 Mar 2026 12:35:16 +0100 Subject: [PATCH 2/2] Remove unused CosmosClientOptions parameter from DI overload --- .../ServiceCollectionExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs b/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs index 196c60d7f..0270b13ea 100644 --- a/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs +++ b/src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs @@ -110,8 +110,7 @@ public static WorkflowOptions UseCosmosDbPersistence( public static WorkflowOptions UseCosmosDbPersistence( this WorkflowOptions options, string databaseId, - CosmosDbStorageOptions cosmosDbStorageOptions = null, - CosmosClientOptions clientOptions = null) + CosmosDbStorageOptions cosmosDbStorageOptions = null) { if (cosmosDbStorageOptions == null) {