Skip to content

Commit ef17734

Browse files
committed
add cosmos mi
1 parent 746bb65 commit ef17734

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/providers/WorkflowCore.Providers.Azure/ServiceCollectionExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,24 @@ public static WorkflowOptions UseCosmosDbPersistence(
4646
options.UsePersistence(sp => new CosmosDbPersistenceProvider(sp.GetService<ICosmosClientFactory>(), databaseId, sp.GetService<ICosmosDbProvisioner>(), cosmosDbStorageOptions));
4747
return options;
4848
}
49+
50+
public static WorkflowOptions UseCosmosDbPersistence(
51+
this WorkflowOptions options,
52+
CosmosClient client,
53+
string databaseId,
54+
CosmosDbStorageOptions cosmosDbStorageOptions = null,
55+
CosmosClientOptions clientOptions = null)
56+
{
57+
if (cosmosDbStorageOptions == null)
58+
{
59+
cosmosDbStorageOptions = new CosmosDbStorageOptions();
60+
}
61+
62+
options.Services.AddSingleton<ICosmosClientFactory>(sp => new CosmosClientFactory(client));
63+
options.Services.AddTransient<ICosmosDbProvisioner>(sp => new CosmosDbProvisioner(sp.GetService<ICosmosClientFactory>(), cosmosDbStorageOptions));
64+
options.Services.AddSingleton<IWorkflowPurger>(sp => new WorkflowPurger(sp.GetService<ICosmosClientFactory>(), databaseId, cosmosDbStorageOptions));
65+
options.UsePersistence(sp => new CosmosDbPersistenceProvider(sp.GetService<ICosmosClientFactory>(), databaseId, sp.GetService<ICosmosDbProvisioner>(), cosmosDbStorageOptions));
66+
return options;
67+
}
4968
}
5069
}

src/providers/WorkflowCore.Providers.Azure/Services/CosmosClientFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public CosmosClientFactory(string connectionString, CosmosClientOptions clientOp
1515
_client = new CosmosClient(connectionString, clientOptions);
1616
}
1717

18+
public CosmosClientFactory(CosmosClient client)
19+
{
20+
_client = client;
21+
}
22+
1823
public CosmosClient GetCosmosClient()
1924
{
2025
return this._client;

0 commit comments

Comments
 (0)