-
-
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.78 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
32 lines (27 loc) · 1.78 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.Data.Common;
using WorkflowCore.Interface;
using WorkflowCore.Models;
using WorkflowCore.Persistence.EntityFramework.Services;
using WorkflowCore.Persistence.SqlServer;
namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
private static readonly Func<SqlContextFactory, bool, bool, IPersistenceProvider> DefaultProviderFactory =
(sqlContextFactory, canCreateDb, canMigrateDb) =>
new EntityFrameworkPersistenceProvider(sqlContextFactory, canCreateDb, canMigrateDb);
private static readonly Func<SqlContextFactory, bool, bool, IPersistenceProvider> OptimizedProviderFactory =
(sqlContextFactory, canCreateDb, canMigrateDb) =>
new LargeDataOptimizedEntityFrameworkPersistenceProvider(sqlContextFactory, canCreateDb, canMigrateDb);
public static WorkflowOptions UseSqlServer(this WorkflowOptions options, string connectionString, bool canCreateDB, bool canMigrateDB, Action<DbConnection> initAction = null) =>
options.UseSqlServer(connectionString, canCreateDB, canMigrateDB, false, initAction);
public static WorkflowOptions UseSqlServer(this WorkflowOptions options, string connectionString, bool canCreateDB, bool canMigrateDB, bool largeDataOptimized, Action<DbConnection> initAction = null)
{
var providerFactory = largeDataOptimized ? OptimizedProviderFactory : DefaultProviderFactory;
options.UsePersistence(_ => providerFactory(new SqlContextFactory(connectionString, initAction), canCreateDB, canMigrateDB));
options.Services.AddTransient<IWorkflowPurger>(sp => new WorkflowPurger(new SqlContextFactory(connectionString, initAction)));
return options;
}
}
}