@@ -15,11 +15,6 @@ namespace React
1515 public class JavaScriptEngineFactory : IDisposable , IJavaScriptEngineFactory
1616 {
1717 /// <summary>
18- /// List of all available JavaScript engines
19- /// </summary>
20- private static readonly IList < FactoryWithPriority > _availableFactories
21- = new List < FactoryWithPriority > ( ) ;
22- /// <summary>
2318 /// Function used to create new JavaScript engine instances.
2419 /// </summary>
2520 private readonly Func < IJsEngine > _factory ;
@@ -32,28 +27,9 @@ private readonly ConcurrentDictionary<int, IJsEngine> _engines
3227 /// <summary>
3328 /// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
3429 /// </summary>
35- public JavaScriptEngineFactory ( )
30+ public JavaScriptEngineFactory ( IEnumerable < Registration > availableFactories )
3631 {
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 ) ;
5733 }
5834
5935 /// <summary>
@@ -93,12 +69,13 @@ public void DisposeEngineForCurrentThread()
9369 }
9470
9571 /// <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.
9774 /// </summary>
9875 /// <returns>Function to create JavaScript engine</returns>
99- private static Func < IJsEngine > GetFactory ( )
76+ private static Func < IJsEngine > GetFactory ( IEnumerable < Registration > availableFactories )
10077 {
101- var availableEngineFactories = _availableFactories
78+ var availableEngineFactories = availableFactories
10279 . OrderBy ( x => x . Priority )
10380 . Select ( x => x . Factory ) ;
10481 foreach ( var engineFactory in availableEngineFactories )
@@ -146,9 +123,20 @@ public void Dispose()
146123 }
147124 }
148125
149- private class FactoryWithPriority
126+ /// <summary>
127+ /// Represents a factory for a supported JavaScript engine.
128+ /// </summary>
129+ public class Registration
150130 {
131+ /// <summary>
132+ /// Gets or sets the factory for this JavaScript engine
133+ /// </summary>
151134 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>
152140 public int Priority { get ; set ; }
153141 }
154142 }
0 commit comments