-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathServiceCollectionExtensions.cs
69 lines (62 loc) · 3.33 KB
/
ServiceCollectionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Logging;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Providers.Azure.Interface;
using WorkflowCore.Providers.Azure.Services;
namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static WorkflowOptions UseAzureSynchronization(this WorkflowOptions options, string connectionString)
{
options.UseQueueProvider(sp => new AzureStorageQueueProvider(connectionString, sp.GetService<ILoggerFactory>()));
options.UseDistributedLockManager(sp => new AzureLockManager(connectionString, sp.GetService<ILoggerFactory>()));
return options;
}
public static WorkflowOptions UseAzureServiceBusEventHub(
this WorkflowOptions options,
string connectionString,
string topicName,
string subscriptionName)
{
options.UseEventHub(sp => new ServiceBusLifeCycleEventHub(
connectionString, topicName, subscriptionName, sp.GetService<ILoggerFactory>()));
return options;
}
public static WorkflowOptions UseCosmosDbPersistence(
this WorkflowOptions options,
string connectionString,
string databaseId,
CosmosDbStorageOptions cosmosDbStorageOptions = null,
CosmosClientOptions clientOptions = null)
{
if (cosmosDbStorageOptions == null)
{
cosmosDbStorageOptions = new CosmosDbStorageOptions();
}
options.Services.AddSingleton<ICosmosClientFactory>(sp => new CosmosClientFactory(connectionString, clientOptions));
options.Services.AddTransient<ICosmosDbProvisioner>(sp => new CosmosDbProvisioner(sp.GetService<ICosmosClientFactory>(), cosmosDbStorageOptions));
options.Services.AddSingleton<IWorkflowPurger>(sp => new WorkflowPurger(sp.GetService<ICosmosClientFactory>(), databaseId, cosmosDbStorageOptions));
options.UsePersistence(sp => new CosmosDbPersistenceProvider(sp.GetService<ICosmosClientFactory>(), databaseId, sp.GetService<ICosmosDbProvisioner>(), cosmosDbStorageOptions));
return options;
}
public static WorkflowOptions UseCosmosDbPersistence(
this WorkflowOptions options,
CosmosClient client,
string databaseId,
CosmosDbStorageOptions cosmosDbStorageOptions = null,
CosmosClientOptions clientOptions = null)
{
if (cosmosDbStorageOptions == null)
{
cosmosDbStorageOptions = new CosmosDbStorageOptions();
}
options.Services.AddSingleton<ICosmosClientFactory>(sp => new CosmosClientFactory(client));
options.Services.AddTransient<ICosmosDbProvisioner>(sp => new CosmosDbProvisioner(sp.GetService<ICosmosClientFactory>(), cosmosDbStorageOptions));
options.Services.AddSingleton<IWorkflowPurger>(sp => new WorkflowPurger(sp.GetService<ICosmosClientFactory>(), databaseId, cosmosDbStorageOptions));
options.UsePersistence(sp => new CosmosDbPersistenceProvider(sp.GetService<ICosmosClientFactory>(), databaseId, sp.GetService<ICosmosDbProvisioner>(), cosmosDbStorageOptions));
return options;
}
}
}