-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
32 lines (27 loc) · 1.77 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
32 lines (27 loc) · 1.77 KB
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
32
using System;
using System.Linq;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Persistence.EntityFramework.Services;
using WorkflowCore.Persistence.PostgreSQL;
namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
private static readonly Func<PostgresContextFactory, bool, bool, IPersistenceProvider> DefaultProviderFactory =
(sqlContextFactory, canCreateDb, canMigrateDb) =>
new EntityFrameworkPersistenceProvider(sqlContextFactory, canCreateDb, canMigrateDb);
private static readonly Func<PostgresContextFactory, bool, bool, IPersistenceProvider> OptimizedProviderFactory =
(sqlContextFactory, canCreateDb, canMigrateDb) =>
new LargeDataOptimizedEntityFrameworkPersistenceProvider(sqlContextFactory, canCreateDb, canMigrateDb);
public static WorkflowOptions UsePostgreSQL(this WorkflowOptions options, string connectionString, bool canCreateDB, bool canMigrateDB, string schemaName = "wfc") =>
options.UsePostgreSQL(connectionString, canCreateDB, canMigrateDB, false, schemaName);
public static WorkflowOptions UsePostgreSQL(this WorkflowOptions options, string connectionString, bool canCreateDB, bool canMigrateDB, bool largeDataOptimized, string schemaName="wfc")
{
var providerFactory = largeDataOptimized ? OptimizedProviderFactory : DefaultProviderFactory;
options.UsePersistence(_ => providerFactory(new PostgresContextFactory(connectionString, schemaName), canCreateDB, canMigrateDB));
options.Services.AddTransient<IWorkflowPurger>(sp => new WorkflowPurger(new PostgresContextFactory(connectionString, schemaName)));
return options;
}
}
}