Skip to content

Commit 2560cda

Browse files
committed
1. In the JsEngineSwitcher class was added the AllowCurrentProperty property (default true);
2. In JavaScriptEngineSwitcher.Extensions.MsDependencyInjection: 2.1. Added support for .NET Standard 2.1; 2.2. `AddJsEngineSwitcher(Action<IJsEngineSwitcher>)` and `AddJsEngineSwitcher(IJsEngineSwitcher, Action<IJsEngineSwitcher>)` extension methods are replaced by new methods accordingly: `AddJsEngineSwitcher(Action<JsEngineSwitcherOptions>)` and `AddJsEngineSwitcher(IJsEngineSwitcher, Action<JsEngineSwitcherOptions>)`; 2.3. `AllowCurrentProperty` property of `JsEngineSwitcherOptions` class allows to forbid usage of the `JsEngineSwitcher.Current` property.
1 parent a22c10e commit 2560cda

File tree

18 files changed

+291
-48
lines changed

18 files changed

+291
-48
lines changed

samples/JavaScriptEngineSwitcher.Sample.AspNetCore1.Mvc1/Startup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ public void ConfigureServices(IServiceCollection services)
5050

5151
// Add JavaScriptEngineSwitcher services to the services container.
5252
services.AddJsEngineSwitcher(options =>
53-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
54-
)
53+
{
54+
options.AllowCurrentProperty = false;
55+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
56+
})
5557
.AddChakraCore()
5658
.AddMsie(options =>
5759
{

samples/JavaScriptEngineSwitcher.Sample.AspNetCore1Full.Mvc1/Startup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ public void ConfigureServices(IServiceCollection services)
5353

5454
// Add JavaScriptEngineSwitcher services to the services container.
5555
services.AddJsEngineSwitcher(options =>
56-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
57-
)
56+
{
57+
options.AllowCurrentProperty = false;
58+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
59+
})
5860
.AddChakraCore()
5961
.AddJurassic()
6062
.AddMsie(options =>

samples/JavaScriptEngineSwitcher.Sample.AspNetCore21.Mvc21/Startup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public void ConfigureServices(IServiceCollection services)
5454

5555
// Add JavaScriptEngineSwitcher services to the services container.
5656
services.AddJsEngineSwitcher(options =>
57-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
58-
)
57+
{
58+
options.AllowCurrentProperty = false;
59+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
60+
})
5961
.AddChakraCore()
6062
.AddJint()
6163
.AddJurassic()

samples/JavaScriptEngineSwitcher.Sample.AspNetCore31.Mvc31/Startup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public void ConfigureServices(IServiceCollection services)
6161

6262
// Add JavaScriptEngineSwitcher services to the services container.
6363
services.AddJsEngineSwitcher(options =>
64-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
65-
)
64+
{
65+
options.AllowCurrentProperty = false;
66+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
67+
})
6668
.AddChakraCore()
6769
.AddJint()
6870
.AddJurassic()

samples/JavaScriptEngineSwitcher.Sample.AspNetCore5.Mvc5/Startup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public void ConfigureServices(IServiceCollection services)
6161

6262
// Add JavaScriptEngineSwitcher services to the services container.
6363
services.AddJsEngineSwitcher(options =>
64-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
65-
)
64+
{
65+
options.AllowCurrentProperty = false;
66+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
67+
})
6668
.AddChakraCore()
6769
.AddJint()
6870
.AddJurassic()

samples/JavaScriptEngineSwitcher.Sample.AspNetCore6.Mvc6/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434

3535
// Add JavaScriptEngineSwitcher services to the services container.
3636
services.AddJsEngineSwitcher(options =>
37-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
38-
)
37+
{
38+
options.AllowCurrentProperty = false;
39+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
40+
})
3941
.AddChakraCore()
4042
.AddJint()
4143
.AddJurassic()

samples/JavaScriptEngineSwitcher.Sample.AspNetCore7.Mvc7/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434

3535
// Add JavaScriptEngineSwitcher services to the services container.
3636
services.AddJsEngineSwitcher(options =>
37-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
38-
)
37+
{
38+
options.AllowCurrentProperty = false;
39+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
40+
})
3941
.AddChakraCore()
4042
.AddJint()
4143
.AddJurassic()

samples/JavaScriptEngineSwitcher.Sample.AspNetCore8.Mvc8/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434

3535
// Add JavaScriptEngineSwitcher services to the services container.
3636
services.AddJsEngineSwitcher(options =>
37-
options.DefaultEngineName = ChakraCoreJsEngine.EngineName
38-
)
37+
{
38+
options.AllowCurrentProperty = false;
39+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
40+
})
3941
.AddChakraCore()
4042
.AddJint()
4143
.AddJurassic()

src/JavaScriptEngineSwitcher.Core/JavaScriptEngineSwitcher.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Description>JavaScript Engine Switcher determines unified interface for access to the basic features of popular JavaScript engines (ChakraCore, Jint, Jurassic, MSIE JavaScript Engine for .NET, NiL.JS, Jering.Javascript.NodeJS, Microsoft ClearScript.V8, VroomJs and YantraJS). This library allows you to quickly and easily switch to using of another JavaScript engine.</Description>
2222
<PackageTags>$(PackageCommonTags)</PackageTags>
2323
<PackageIconFullPath>../../Icons/JavaScriptEngineSwitcher_Core_Logo128x128.png</PackageIconFullPath>
24+
<PackageReleaseNotes>In the `JsEngineSwitcher` class was added the `AllowCurrentProperty` property (default `true`).</PackageReleaseNotes>
2425
</PropertyGroup>
2526

2627
<ItemGroup>

src/JavaScriptEngineSwitcher.Core/JsEngineSwitcher.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace JavaScriptEngineSwitcher.Core
99
/// </summary>
1010
public sealed class JsEngineSwitcher : IJsEngineSwitcher
1111
{
12+
/// <summary>
13+
/// Flag for whether to allow usage of the <see cref="Current"/> property
14+
/// </summary>
15+
private static bool _allowCurrentProperty = true;
16+
1217
/// <summary>
1318
/// Default instance of JS engine switcher
1419
/// </summary>
@@ -20,17 +25,42 @@ private static readonly Lazy<IJsEngineSwitcher> _default
2025
/// </summary>
2126
private static IJsEngineSwitcher _current;
2227

28+
/// <summary>
29+
/// Gets or sets a flag for whether to allow usage of the <see cref="Current"/> property
30+
/// </summary>
31+
/// <remarks>
32+
/// Required to ensure the usage of an instance of the JS engine switcher that is registered by using
33+
/// the <c>IServiceCollection</c> interface.
34+
/// </remarks>
35+
public static bool AllowCurrentProperty
36+
{
37+
get { return _allowCurrentProperty; }
38+
set { _allowCurrentProperty = value; }
39+
}
40+
2341
/// <summary>
2442
/// Gets or sets a instance of JS engine switcher
2543
/// </summary>
2644
public static IJsEngineSwitcher Current
2745
{
2846
get
2947
{
48+
if (!_allowCurrentProperty)
49+
{
50+
throw new InvalidOperationException(
51+
Strings.Configuration_GettingFromJsEngineSwitcherCurrentPropertyForbidden);
52+
}
53+
3054
return _current ?? _default.Value;
3155
}
3256
set
3357
{
58+
if (!_allowCurrentProperty)
59+
{
60+
throw new InvalidOperationException(
61+
Strings.Configuration_AssigningToJsEngineSwitcherCurrentPropertyForbidden);
62+
}
63+
3464
_current = value;
3565
}
3666
}

0 commit comments

Comments
 (0)