1
1
using System ;
2
+ using System . Collections . Concurrent ;
2
3
using System . Collections . Generic ;
3
4
using System . Linq ;
4
5
using System . Threading . Tasks ;
@@ -14,11 +15,26 @@ namespace WorkflowCore.Services
14
15
/// </summary>
15
16
public class MemoryPersistenceProvider : IPersistenceProvider
16
17
{
18
+ private static readonly ConcurrentDictionary < string , Tuple < List < WorkflowInstance > , List < EventSubscription > , List < Event > , List < ExecutionError > > > Environments =
19
+ new ConcurrentDictionary < string , Tuple < List < WorkflowInstance > , List < EventSubscription > , List < Event > , List < ExecutionError > > > ( ) ;
20
+ private readonly List < WorkflowInstance > _instances ;
21
+ private readonly List < EventSubscription > _subscriptions ;
22
+ private readonly List < Event > _events ;
23
+ private readonly List < ExecutionError > _errors ;
24
+
25
+ public MemoryPersistenceProvider ( )
26
+ : this ( "" )
27
+ {
28
+ }
17
29
18
- private static List < WorkflowInstance > _instances = new List < WorkflowInstance > ( ) ;
19
- private static List < EventSubscription > _subscriptions = new List < EventSubscription > ( ) ;
20
- private static List < Event > _events = new List < Event > ( ) ;
21
- private static List < ExecutionError > _errors = new List < ExecutionError > ( ) ;
30
+ public MemoryPersistenceProvider ( string environmentKey )
31
+ {
32
+ var environment = Environments . GetOrAdd ( environmentKey , _ => Tuple . Create ( new List < WorkflowInstance > ( ) , new List < EventSubscription > ( ) , new List < Event > ( ) , new List < ExecutionError > ( ) ) ) ;
33
+ _instances = environment . Item1 ;
34
+ _subscriptions = environment . Item2 ;
35
+ _events = environment . Item3 ;
36
+ _errors = environment . Item4 ;
37
+ }
22
38
23
39
public async Task < string > CreateNewWorkflow ( WorkflowInstance workflow )
24
40
{
0 commit comments