11using System ;
22using Amazon ;
33using Amazon . DynamoDBv2 ;
4+ using Amazon . Kinesis ;
45using Amazon . Runtime ;
56using Amazon . SQS ;
67using Microsoft . Extensions . Logging ;
@@ -15,28 +16,55 @@ public static class ServiceCollectionExtensions
1516 {
1617 public static WorkflowOptions UseAwsSimpleQueueService ( this WorkflowOptions options , AWSCredentials credentials , AmazonSQSConfig config , string queuesPrefix = "workflowcore" )
1718 {
18- options . UseQueueProvider ( sp => new SQSQueueProvider ( credentials , config , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
19+ var sqsClient = new AmazonSQSClient ( credentials , config ) ;
20+ return options . UseAwsSimpleQueueServiceWithProvisionedClient ( sqsClient , queuesPrefix ) ;
21+ }
22+
23+ public static WorkflowOptions UseAwsSimpleQueueServiceWithProvisionedClient ( this WorkflowOptions options , AmazonSQSClient sqsClient , string queuesPrefix = "workflowcore" )
24+ {
25+ options . UseQueueProvider ( sp => new SQSQueueProvider ( sqsClient , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
1926 return options ;
2027 }
2128
2229 public static WorkflowOptions UseAwsDynamoLocking ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tableName )
2330 {
24- options . UseDistributedLockManager ( sp => new DynamoLockProvider ( credentials , config , tableName , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
31+ var dbClient = new AmazonDynamoDBClient ( credentials , config ) ;
32+ return options . UseAwsDynamoLockingWithProvisionedClient ( dbClient , tableName ) ;
33+ }
34+
35+ public static WorkflowOptions UseAwsDynamoLockingWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tableName )
36+ {
37+ options . UseDistributedLockManager ( sp => new DynamoLockProvider ( dynamoClient , tableName , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
2538 return options ;
2639 }
2740
2841 public static WorkflowOptions UseAwsDynamoPersistence ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tablePrefix )
2942 {
30- options . Services . AddTransient < IDynamoDbProvisioner > ( sp => new DynamoDbProvisioner ( credentials , config , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
31- options . UsePersistence ( sp => new DynamoPersistenceProvider ( credentials , config , sp . GetService < IDynamoDbProvisioner > ( ) , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
43+ var dbClient = new AmazonDynamoDBClient ( credentials , config ) ;
44+ return options . UseAwsDynamoPersistenceWithProvisionedClient ( dbClient , tablePrefix ) ;
45+ }
46+
47+ public static WorkflowOptions UseAwsDynamoPersistenceWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tablePrefix )
48+ {
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 > ( ) ) ) ;
3251 return options ;
3352 }
3453
3554 public static WorkflowOptions UseAwsKinesis ( this WorkflowOptions options , AWSCredentials credentials , RegionEndpoint region , string appName , string streamName )
3655 {
37- options . Services . AddTransient < IKinesisTracker > ( sp => new KinesisTracker ( credentials , region , "workflowcore_kinesis" , sp . GetService < ILoggerFactory > ( ) ) ) ;
38- options . Services . AddTransient < IKinesisStreamConsumer > ( sp => new KinesisStreamConsumer ( credentials , region , sp . GetService < IKinesisTracker > ( ) , sp . GetService < IDistributedLockProvider > ( ) , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
39- 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 options . UseAwsKinesisWithProvisionedClients ( 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 > ( ) ) ) ;
4068 return options ;
4169 }
4270 }
0 commit comments