-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
142 lines (127 loc) · 7.03 KB
/
Copy pathServiceCollectionExtensions.cs
File metadata and controls
142 lines (127 loc) · 7.03 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using Azure.Core;
using Azure.Data.Tables;
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 UseAzureSynchronization(this WorkflowOptions options, Uri blobEndpoint, Uri queueEndpoint, TokenCredential tokenCredential)
{
options.UseQueueProvider(sp => new AzureStorageQueueProvider(queueEndpoint, tokenCredential, sp.GetService<ILoggerFactory>()));
options.UseDistributedLockManager(sp => new AzureLockManager(blobEndpoint, tokenCredential, 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 UseAzureServiceBusEventHub(
this WorkflowOptions options,
string fullyQualifiedNamespace,
TokenCredential tokenCredential,
string topicName,
string subscriptionName)
{
options.UseEventHub(sp => new ServiceBusLifeCycleEventHub(
fullyQualifiedNamespace, tokenCredential, 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;
}
public static WorkflowOptions UseCosmosDbPersistence(
this WorkflowOptions options,
string accountEndpoint,
TokenCredential tokenCredential,
string databaseId,
CosmosDbStorageOptions cosmosDbStorageOptions = null)
{
if (cosmosDbStorageOptions == null)
{
cosmosDbStorageOptions = new CosmosDbStorageOptions();
}
options.Services.AddSingleton<ICosmosClientFactory>(sp => new CosmosClientFactory(accountEndpoint, tokenCredential));
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 UseAzureTableStoragePersistence(
this WorkflowOptions options,
string connectionString,
string tableNamePrefix = "WorkflowCore")
{
options.Services.AddSingleton<TableServiceClient>(sp => new TableServiceClient(connectionString));
options.UsePersistence(sp => new AzureTableStoragePersistenceProvider(sp.GetService<TableServiceClient>(), tableNamePrefix, sp.GetService<ILoggerFactory>()));
return options;
}
public static WorkflowOptions UseAzureTableStoragePersistence(
this WorkflowOptions options,
TableServiceClient tableServiceClient,
string tableNamePrefix = "WorkflowCore")
{
options.Services.AddSingleton(tableServiceClient);
options.UsePersistence(sp => new AzureTableStoragePersistenceProvider(sp.GetService<TableServiceClient>(), tableNamePrefix, sp.GetService<ILoggerFactory>()));
return options;
}
public static WorkflowOptions UseAzureTableStoragePersistence(
this WorkflowOptions options,
Uri serviceUri,
TokenCredential tokenCredential,
string tableNamePrefix = "WorkflowCore")
{
options.Services.AddSingleton<TableServiceClient>(sp => new TableServiceClient(serviceUri, tokenCredential));
options.UsePersistence(sp => new AzureTableStoragePersistenceProvider(sp.GetService<TableServiceClient>(), tableNamePrefix, sp.GetService<ILoggerFactory>()));
return options;
}
}
}