11using System ;
22using Amazon ;
33using Amazon . DynamoDBv2 ;
4+ using Amazon . Kinesis ;
45using Amazon . Runtime ;
56using Amazon . SQS ;
67using Microsoft . Extensions . Logging ;
@@ -15,47 +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 , null , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
19- return options ;
19+ var sqsClient = new AmazonSQSClient ( credentials , config ) ;
20+ return UseAwsSimpleQueueServiceWithProvisionedClient ( options , sqsClient , queuesPrefix ) ;
2021 }
2122
2223 public static WorkflowOptions UseAwsSimpleQueueServiceWithProvisionedClient ( this WorkflowOptions options , AmazonSQSClient sqsClient , string queuesPrefix = "workflowcore" )
2324 {
24- options . UseQueueProvider ( sp => new SQSQueueProvider ( null , null , sqsClient , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
25+ options . UseQueueProvider ( sp => new SQSQueueProvider ( sqsClient , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
2526 return options ;
2627 }
2728
2829 public static WorkflowOptions UseAwsDynamoLocking ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tableName )
2930 {
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 ) ;
3233 }
3334
3435 public static WorkflowOptions UseAwsDynamoLockingWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tableName )
3536 {
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 > ( ) ) ) ;
3738 return options ;
3839 }
3940
4041 public static WorkflowOptions UseAwsDynamoPersistence ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tablePrefix )
4142 {
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 ) ;
4545 }
4646
4747 public static WorkflowOptions UseAwsDynamoPersistenceWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tablePrefix )
4848 {
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 > ( ) ) ) ;
5151 return options ;
5252 }
5353
5454 public static WorkflowOptions UseAwsKinesis ( this WorkflowOptions options , AWSCredentials credentials , RegionEndpoint region , string appName , string streamName )
5555 {
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 > ( ) ) ) ;
5968 return options ;
6069 }
6170 }
0 commit comments