1
1
using System ;
2
2
using Amazon ;
3
3
using Amazon . DynamoDBv2 ;
4
+ using Amazon . Kinesis ;
4
5
using Amazon . Runtime ;
5
6
using Amazon . SQS ;
6
7
using Microsoft . Extensions . Logging ;
@@ -15,47 +16,55 @@ public static class ServiceCollectionExtensions
15
16
{
16
17
public static WorkflowOptions UseAwsSimpleQueueService ( this WorkflowOptions options , AWSCredentials credentials , AmazonSQSConfig config , string queuesPrefix = "workflowcore" )
17
18
{
18
- options . UseQueueProvider ( sp => new SQSQueueProvider ( credentials , config , null , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
19
- return options ;
19
+ var sqsClient = new AmazonSQSClient ( credentials , config ) ;
20
+ return UseAwsSimpleQueueServiceWithProvisionedClient ( options , sqsClient , queuesPrefix ) ;
20
21
}
21
22
22
23
public static WorkflowOptions UseAwsSimpleQueueServiceWithProvisionedClient ( this WorkflowOptions options , AmazonSQSClient sqsClient , string queuesPrefix = "workflowcore" )
23
24
{
24
- options . UseQueueProvider ( sp => new SQSQueueProvider ( null , null , sqsClient , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
25
+ options . UseQueueProvider ( sp => new SQSQueueProvider ( sqsClient , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
25
26
return options ;
26
27
}
27
28
28
29
public static WorkflowOptions UseAwsDynamoLocking ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tableName )
29
30
{
30
- options . UseDistributedLockManager ( sp => new DynamoLockProvider ( credentials , config , null , tableName , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
31
- return options ;
31
+ var dbClient = new AmazonDynamoDBClient ( credentials , config ) ;
32
+ return UseAwsDynamoLockingWithProvisionedClient ( options , dbClient , tableName ) ;
32
33
}
33
34
34
35
public static WorkflowOptions UseAwsDynamoLockingWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tableName )
35
36
{
36
- options . UseDistributedLockManager ( sp => new DynamoLockProvider ( null , null , dynamoClient , tableName , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
37
+ options . UseDistributedLockManager ( sp => new DynamoLockProvider ( dynamoClient , tableName , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
37
38
return options ;
38
39
}
39
40
40
41
public static WorkflowOptions UseAwsDynamoPersistence ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tablePrefix )
41
42
{
42
- options . Services . AddTransient < IDynamoDbProvisioner > ( sp => new DynamoDbProvisioner ( credentials , config , null , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
43
- options . UsePersistence ( sp => new DynamoPersistenceProvider ( credentials , config , null , sp . GetService < IDynamoDbProvisioner > ( ) , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
44
- return options ;
43
+ var dbClient = new AmazonDynamoDBClient ( credentials , config ) ;
44
+ return UseAwsDynamoPersistenceWithProvisionedClient ( options , dbClient , tablePrefix ) ;
45
45
}
46
46
47
47
public static WorkflowOptions UseAwsDynamoPersistenceWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tablePrefix )
48
48
{
49
- options . Services . AddTransient < IDynamoDbProvisioner > ( sp => new DynamoDbProvisioner ( null , null , dynamoClient , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
50
- options . UsePersistence ( sp => new DynamoPersistenceProvider ( null , null , dynamoClient , sp . GetService < IDynamoDbProvisioner > ( ) , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
49
+ options . Services . AddTransient < IDynamoDbProvisioner > ( sp => new DynamoDbProvisioner ( dynamoClient , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
50
+ options . UsePersistence ( sp => new DynamoPersistenceProvider ( dynamoClient , sp . GetService < IDynamoDbProvisioner > ( ) , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
51
51
return options ;
52
52
}
53
53
54
54
public static WorkflowOptions UseAwsKinesis ( this WorkflowOptions options , AWSCredentials credentials , RegionEndpoint region , string appName , string streamName )
55
55
{
56
- options . Services . AddTransient < IKinesisTracker > ( sp => new KinesisTracker ( credentials , region , "workflowcore_kinesis" , sp . GetService < ILoggerFactory > ( ) ) ) ;
57
- options . Services . AddTransient < IKinesisStreamConsumer > ( sp => new KinesisStreamConsumer ( credentials , region , sp . GetService < IKinesisTracker > ( ) , sp . GetService < IDistributedLockProvider > ( ) , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
58
- options . UseEventHub ( sp => new KinesisProvider ( credentials , region , appName , streamName , sp . GetService < IKinesisStreamConsumer > ( ) , sp . GetService < ILoggerFactory > ( ) ) ) ;
56
+ var kinesisClient = new AmazonKinesisClient ( credentials , region ) ;
57
+ var dynamoClient = new AmazonDynamoDBClient ( credentials , region ) ;
58
+
59
+ return UseAwsKinesisWithProvisionedClients ( options , kinesisClient , dynamoClient , appName , streamName ) ;
60
+
61
+ }
62
+
63
+ public static WorkflowOptions UseAwsKinesisWithProvisionedClients ( this WorkflowOptions options , AmazonKinesisClient kinesisClient , AmazonDynamoDBClient dynamoDbClient , string appName , string streamName )
64
+ {
65
+ options . Services . AddTransient < IKinesisTracker > ( sp => new KinesisTracker ( dynamoDbClient , "workflowcore_kinesis" , sp . GetService < ILoggerFactory > ( ) ) ) ;
66
+ options . Services . AddTransient < IKinesisStreamConsumer > ( sp => new KinesisStreamConsumer ( kinesisClient , sp . GetService < IKinesisTracker > ( ) , sp . GetService < IDistributedLockProvider > ( ) , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
67
+ options . UseEventHub ( sp => new KinesisProvider ( kinesisClient , appName , streamName , sp . GetService < IKinesisStreamConsumer > ( ) , sp . GetService < ILoggerFactory > ( ) ) ) ;
59
68
return options ;
60
69
}
61
70
}
0 commit comments