Skip to content

Commit b68bb06

Browse files
committed
Revert and provide a new extension for creating db from outside
1 parent 66fc797 commit b68bb06

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/providers/WorkflowCore.Persistence.MongoDB/ServiceCollectionExtensions.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using MongoDB.Driver;
22
using System;
3-
using System.Linq;
43
using WorkflowCore.Interface;
54
using WorkflowCore.Models;
65
using WorkflowCore.Persistence.MongoDB.Services;
@@ -33,5 +32,26 @@ public static WorkflowOptions UseMongoDB(
3332
});
3433
return options;
3534
}
35+
36+
public static WorkflowOptions UseMongoDB(
37+
this WorkflowOptions options,
38+
Func<IServiceProvider, IMongoDatabase> createDatabase)
39+
{
40+
if (options == null) throw new ArgumentNullException(nameof(options));
41+
if (createDatabase == null) throw new ArgumentNullException(nameof(createDatabase));
42+
43+
options.UsePersistence(sp =>
44+
{
45+
var db = createDatabase(sp);
46+
return new MongoPersistenceProvider(db);
47+
});
48+
options.Services.AddTransient<IWorkflowPurger>(sp =>
49+
{
50+
var db = createDatabase(sp);
51+
return new WorkflowPurger(db);
52+
});
53+
54+
return options;
55+
}
3656
}
3757
}

src/providers/WorkflowCore.Persistence.MongoDB/Services/MongoPersistenceProvider.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using WorkflowCore.Interface;
1313
using WorkflowCore.Models;
1414
using System.Threading;
15-
using MongoDB.Extensions.Transactions;
1615

1716
namespace WorkflowCore.Persistence.MongoDB.Services
1817
{
@@ -116,13 +115,13 @@ static void CreateIndexes(MongoPersistenceProvider instance)
116115
}
117116
}
118117

119-
private IMongoCollection<WorkflowInstance> WorkflowInstances => _database.GetCollection<WorkflowInstance>(WorkflowCollectionName).AsTransactionCollection();
118+
private IMongoCollection<WorkflowInstance> WorkflowInstances => _database.GetCollection<WorkflowInstance>(WorkflowCollectionName);
120119

121-
private IMongoCollection<EventSubscription> EventSubscriptions => _database.GetCollection<EventSubscription>("wfc.subscriptions").AsTransactionCollection();
120+
private IMongoCollection<EventSubscription> EventSubscriptions => _database.GetCollection<EventSubscription>("wfc.subscriptions");
122121

123-
private IMongoCollection<Event> Events => _database.GetCollection<Event>("wfc.events").AsTransactionCollection();
122+
private IMongoCollection<Event> Events => _database.GetCollection<Event>("wfc.events");
124123

125-
private IMongoCollection<ExecutionError> ExecutionErrors => _database.GetCollection<ExecutionError>("wfc.execution_errors").AsTransactionCollection();
124+
private IMongoCollection<ExecutionError> ExecutionErrors => _database.GetCollection<ExecutionError>("wfc.execution_errors");
126125

127126
public async Task<string> CreateNewWorkflow(WorkflowInstance workflow, CancellationToken cancellationToken = default)
128127
{

src/providers/WorkflowCore.Persistence.MongoDB/WorkflowCore.Persistence.MongoDB.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="MongoDB.Driver" Version="2.12.2" />
26-
<PackageReference Include="MongoDB.Extensions.Transactions" Version="0.8.0" />
25+
<PackageReference Include="MongoDB.Driver" Version="2.8.1" />
2726
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
2827
</ItemGroup>
2928

0 commit comments

Comments
 (0)