-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureOneSQLExtensions.cs
More file actions
36 lines (34 loc) · 1.53 KB
/
FeatureOneSQLExtensions.cs
File metadata and controls
36 lines (34 loc) · 1.53 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
33
34
35
36
using System;
using FeatureOne.Cache;
using FeatureOne.Json;
using FeatureOne.SQL.StorageProvider;
using Microsoft.Extensions.DependencyInjection;
namespace FeatureOne.SQL.Extensions
{
/// <summary>
/// Extension methods for adding FeatureOne services to the DI container
/// </summary>
public static class FeatureOneSQLExtensions
{
/// <summary>
/// Add Feature One with SQL storage.
/// </summary>
/// <param name="services"></param>
/// <param name="configuration">Required: SQL Configuration.</param>
/// <param name="deserializer">Optional: Custom Deserializer for Toggles. Pass Null to use default.</param>
/// <param name="cache">Optional: Custom Cache for Toggles. Pass Null to use default memCache.</param>
/// <returns></returns>
public static IServiceCollection AddFeatureOneWithSQLStorage(this IServiceCollection services,
SQLConfiguration configuration, IToggleDeserializer deserializer = null, ICache cache = null)
{
if (configuration == null)
throw new ArgumentNullException("SQLConfiguration is required.");
return services
.AddFeatureOne(provider =>
new SQLStorageProvider(repository: new DbRepository(configuration),
deserializer: deserializer ?? new ToggleDeserializer(new ConditionDeserializer()),
cache: cache ?? new FeatureCache(),
cacheSettings: configuration.CacheSettings));
}
}
}