forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsEngineSwitcherServiceCollectionExtensions.cs
More file actions
59 lines (49 loc) · 1.78 KB
/
JsEngineSwitcherServiceCollectionExtensions.cs
File metadata and controls
59 lines (49 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using Microsoft.Extensions.DependencyInjection;
using JavaScriptEngineSwitcher.Core;
namespace JavaScriptEngineSwitcher.Extensions.MsDependencyInjection
{
/// <summary>
/// Extension methods for adding the JS engine switcher in an <see cref="IServiceCollection" />
/// </summary>
public static class JsEngineSwitcherServiceCollectionExtensions
{
/// <summary>
/// Adds a JS engine switcher to <see cref="IServiceCollection"/>
/// </summary>
/// <param name="services">The services available in the application</param>
/// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
public static JsEngineFactoryCollection AddJsEngineSwitcher(this IServiceCollection services)
{
if (services == null)
{
throw new ArgumentNullException("services");
}
JsEngineSwitcher engineSwitcher = JsEngineSwitcher.Instance;
services.AddSingleton(engineSwitcher);
return engineSwitcher.EngineFactories;
}
/// <summary>
/// Adds a JS engine switcher to <see cref="IServiceCollection"/>
/// </summary>
/// <param name="services">The services available in the application</param>
/// <param name="configure">The <see cref="JsEngineSwitcher"/> which need to be configured</param>
/// <returns>Instance of <see cref="JsEngineFactoryCollection" /></returns>
public static JsEngineFactoryCollection AddJsEngineSwitcher(this IServiceCollection services,
Action<JsEngineSwitcher> configure)
{
if (services == null)
{
throw new ArgumentNullException("services");
}
if (configure == null)
{
throw new ArgumentNullException("configure");
}
JsEngineSwitcher engineSwitcher = JsEngineSwitcher.Instance;
configure(engineSwitcher);
services.AddSingleton(engineSwitcher);
return engineSwitcher.EngineFactories;
}
}
}