@@ -15,11 +15,6 @@ namespace React
15
15
public class JavaScriptEngineFactory : IDisposable , IJavaScriptEngineFactory
16
16
{
17
17
/// <summary>
18
- /// List of all available JavaScript engines
19
- /// </summary>
20
- private static readonly IList < FactoryWithPriority > _availableFactories
21
- = new List < FactoryWithPriority > ( ) ;
22
- /// <summary>
23
18
/// Function used to create new JavaScript engine instances.
24
19
/// </summary>
25
20
private readonly Func < IJsEngine > _factory ;
@@ -32,28 +27,9 @@ private readonly ConcurrentDictionary<int, IJsEngine> _engines
32
27
/// <summary>
33
28
/// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
34
29
/// </summary>
35
- public JavaScriptEngineFactory ( )
30
+ public JavaScriptEngineFactory ( IEnumerable < Registration > availableFactories )
36
31
{
37
- _factory = GetFactory ( ) ;
38
- }
39
-
40
- /// <summary>
41
- /// Adds a supported JavaScript engine. When an instance of
42
- /// <see cref="JavaScriptEngineFactory" /> is created, the first functioning JavaScript
43
- /// engine with the lowest priority will be used.
44
- /// </summary>
45
- /// <param name="factory">Factory method to create new instance of the engine</param>
46
- /// <param name="priority">
47
- /// Any number. All engines will be sorted by priority, so "better" engines should have
48
- /// a lower priority number.
49
- /// </param>
50
- public static void AddFactoryWithPriority ( Func < IJsEngine > factory , int priority )
51
- {
52
- _availableFactories . Add ( new FactoryWithPriority
53
- {
54
- Factory = factory ,
55
- Priority = priority
56
- } ) ;
32
+ _factory = GetFactory ( availableFactories ) ;
57
33
}
58
34
59
35
/// <summary>
@@ -93,12 +69,13 @@ public void DisposeEngineForCurrentThread()
93
69
}
94
70
95
71
/// <summary>
96
- /// Gets a factory for the most appropriate JavaScript engine for the current environment
72
+ /// Gets a factory for the most appropriate JavaScript engine for the current environment.
73
+ /// The first functioning JavaScript engine with the lowest priority will be used.
97
74
/// </summary>
98
75
/// <returns>Function to create JavaScript engine</returns>
99
- private static Func < IJsEngine > GetFactory ( )
76
+ private static Func < IJsEngine > GetFactory ( IEnumerable < Registration > availableFactories )
100
77
{
101
- var availableEngineFactories = _availableFactories
78
+ var availableEngineFactories = availableFactories
102
79
. OrderBy ( x => x . Priority )
103
80
. Select ( x => x . Factory ) ;
104
81
foreach ( var engineFactory in availableEngineFactories )
@@ -146,9 +123,20 @@ public void Dispose()
146
123
}
147
124
}
148
125
149
- private class FactoryWithPriority
126
+ /// <summary>
127
+ /// Represents a factory for a supported JavaScript engine.
128
+ /// </summary>
129
+ public class Registration
150
130
{
131
+ /// <summary>
132
+ /// Gets or sets the factory for this JavaScript engine
133
+ /// </summary>
151
134
public Func < IJsEngine > Factory { get ; set ; }
135
+
136
+ /// <summary>
137
+ /// Gets or sets the priority for this JavaScript engine. Engines with lower priority
138
+ /// are preferred.
139
+ /// </summary>
152
140
public int Priority { get ; set ; }
153
141
}
154
142
}
0 commit comments