forked from danielgerlag/workflow-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServiceCollectionExtensions.cs
31 lines (30 loc) · 1013 Bytes
/
ServiceCollectionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Persistence.MongoDB.Services;
namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
public static WorkflowOptions UseMongoDB(this WorkflowOptions options, string mongoUrl, string databaseName)
{
options.UsePersistence(sp =>
{
var client = new MongoClient(mongoUrl);
var db = client.GetDatabase(databaseName);
return new MongoPersistenceProvider(db);
});
options.Services.AddTransient<IWorkflowPurger>(sp =>
{
var client = new MongoClient(mongoUrl);
var db = client.GetDatabase(databaseName);
return new WorkflowPurger(db);
});
return options;
}
}
}