Skip to content

Commit 8ccc562

Browse files
committed
In test and sample projects added support for .NET 10
1 parent 2be7421 commit 8ccc562

File tree

22 files changed

+592
-38
lines changed

22 files changed

+592
-38
lines changed

JavaScriptEngineSwitcher.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@
8181
<Project Path="samples/JavaScriptEngineSwitcher.Sample.AspNetCore7.Mvc7/JavaScriptEngineSwitcher.Sample.AspNetCore7.Mvc7.csproj" />
8282
<Project Path="samples/JavaScriptEngineSwitcher.Sample.AspNetCore8.Mvc8/JavaScriptEngineSwitcher.Sample.AspNetCore8.Mvc8.csproj" />
8383
<Project Path="samples/JavaScriptEngineSwitcher.Sample.AspNetCore9.Mvc9/JavaScriptEngineSwitcher.Sample.AspNetCore9.Mvc9.csproj" />
84+
<Project Path="samples/JavaScriptEngineSwitcher.Sample.AspNetCore10.Mvc10/JavaScriptEngineSwitcher.Sample.AspNetCore10.Mvc10.csproj" />
8485
</Folder>
8586
</Solution>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.0",
3+
"version": "10.0.100",
44
"rollForward": "latestFeature"
55
}
66
}

samples/JavaScriptEngineSwitcher.Sample.AspNetCore.Infrastructure/JavaScriptEngineSwitcher.Sample.AspNetCore.Infrastructure.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Product>JS Engine Switcher: Infrastructure for ASP.NET Core Samples</Product>
55
<VersionPrefix>3.30.2</VersionPrefix>
6-
<TargetFrameworks>net451;netstandard1.6;netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
6+
<TargetFrameworks>net451;netstandard1.6;netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
77
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard1.6' ">1.6.0</NetStandardImplicitPackageVersion>
88
<OutputType>Library</OutputType>
99
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -42,11 +42,15 @@
4242
</ItemGroup>
4343

4444
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
45-
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="8.0.17" />
45+
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="8.0.22" />
4646
</ItemGroup>
4747

4848
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
49-
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="9.0.6" />
49+
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="9.0.11" />
50+
</ItemGroup>
51+
52+
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0' ">
53+
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="10.0.0" />
5054
</ItemGroup>
5155

5256
</Project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Diagnostics;
2+
using System.Threading.Tasks;
3+
4+
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Html;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Configuration;
8+
9+
using JavaScriptEngineSwitcher.Sample.AspNetCore9.Mvc9.Models;
10+
using JavaScriptEngineSwitcher.Sample.Logic.Models;
11+
using JavaScriptEngineSwitcher.Sample.Logic.Services;
12+
13+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore9.Mvc9.Controllers
14+
{
15+
public class HomeController : Controller
16+
{
17+
private readonly FileContentService _fileContentService;
18+
private readonly JsEvaluationService _jsEvaluationService;
19+
20+
21+
public HomeController(
22+
IConfigurationRoot configuration,
23+
IWebHostEnvironment hostingEnvironment,
24+
JsEvaluationService jsEvaluationService)
25+
{
26+
string textContentDirectoryPath = configuration
27+
.GetSection("jsengineswitcher")
28+
.GetSection("Samples")["TextContentDirectoryPath"]
29+
;
30+
31+
_fileContentService = new FileContentService(textContentDirectoryPath, hostingEnvironment);
32+
_jsEvaluationService = jsEvaluationService;
33+
}
34+
35+
36+
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
37+
public IActionResult Index()
38+
{
39+
ViewBag.Body = new HtmlString(_fileContentService.GetFileContent("index.html"));
40+
41+
return View();
42+
}
43+
44+
[HttpGet]
45+
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
46+
public IActionResult Demo()
47+
{
48+
var model = _jsEvaluationService.GetInitializationData();
49+
50+
return View(model);
51+
}
52+
53+
[HttpPost]
54+
public async Task<IActionResult> Demo(JsEvaluationViewModel editedModel)
55+
{
56+
var model = _jsEvaluationService.GetInitializationData();
57+
await TryUpdateModelAsync(model, string.Empty, m => m.EngineName, m=> m.Expression);
58+
59+
if (ModelState.IsValid)
60+
{
61+
model = _jsEvaluationService.Evaluate(model);
62+
63+
ModelState.Clear();
64+
}
65+
66+
return View(model);
67+
}
68+
69+
[ResponseCache(CacheProfileName = "CacheCompressedContent5Minutes")]
70+
public IActionResult Contact()
71+
{
72+
ViewBag.Body = new HtmlString(_fileContentService.GetFileContent("contact.html"));
73+
74+
return View();
75+
}
76+
77+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
78+
public IActionResult Error()
79+
{
80+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
81+
}
82+
}
83+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<Product>JS Engine Switcher: Sample ASP.NET Core 10.0 MVC 10 Site</Product>
5+
<VersionPrefix>3.30.2</VersionPrefix>
6+
<TargetFramework>net10.0</TargetFramework>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<OutputType>Exe</OutputType>
9+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
10+
<PreserveCompilationContext>true</PreserveCompilationContext>
11+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
12+
<IsPackable>false</IsPackable>
13+
</PropertyGroup>
14+
15+
<Import Project="../../build/common.props" />
16+
17+
<ItemGroup>
18+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" />
19+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" />
20+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-arm" />
21+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-arm64" />
22+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" />
23+
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x86" />
24+
<PackageReference Include="Microsoft.ClearScript.V8.Native.linux-arm" />
25+
<PackageReference Include="Microsoft.ClearScript.V8.Native.linux-arm64" />
26+
<PackageReference Include="Microsoft.ClearScript.V8.Native.linux-x64" />
27+
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-arm64" />
28+
<PackageReference Include="Microsoft.ClearScript.V8.Native.osx-x64" />
29+
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-arm64" />
30+
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" />
31+
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x86" />
32+
33+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.ChakraCore/JavaScriptEngineSwitcher.ChakraCore.csproj" />
34+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Extensions.MsDependencyInjection/JavaScriptEngineSwitcher.Extensions.MsDependencyInjection.csproj" />
35+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Jint/JavaScriptEngineSwitcher.Jint.csproj" />
36+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Jurassic/JavaScriptEngineSwitcher.Jurassic.csproj" />
37+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Msie/JavaScriptEngineSwitcher.Msie.csproj" />
38+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.NiL/JavaScriptEngineSwitcher.NiL.csproj" />
39+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Node/JavaScriptEngineSwitcher.Node.csproj" />
40+
<ProjectReference Include="../JavaScriptEngineSwitcher.Sample.AspNetCore.Infrastructure/JavaScriptEngineSwitcher.Sample.AspNetCore.Infrastructure.csproj" />
41+
<ProjectReference Include="../JavaScriptEngineSwitcher.Sample.Logic/JavaScriptEngineSwitcher.Sample.Logic.csproj" />
42+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.csproj" />
43+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Vroom/JavaScriptEngineSwitcher.Vroom.csproj" />
44+
<ProjectReference Include="../../src/JavaScriptEngineSwitcher.Yantra/JavaScriptEngineSwitcher.Yantra.csproj" />
45+
</ItemGroup>
46+
47+
<Import Project="../JavaScriptEngineSwitcher.Sample.AspNetCore.ClientSideAssets/ensure-client-side-assets-builded.targets" />
48+
49+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace JavaScriptEngineSwitcher.Sample.AspNetCore9.Mvc9.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using Jering.Javascript.NodeJS;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
using JavaScriptEngineSwitcher.ChakraCore;
5+
using JavaScriptEngineSwitcher.Extensions.MsDependencyInjection;
6+
using JavaScriptEngineSwitcher.Jint;
7+
using JavaScriptEngineSwitcher.Jurassic;
8+
using JavaScriptEngineSwitcher.Msie;
9+
using JavaScriptEngineSwitcher.NiL;
10+
using JavaScriptEngineSwitcher.Node;
11+
using JavaScriptEngineSwitcher.Sample.Logic.Services;
12+
using JavaScriptEngineSwitcher.V8;
13+
using JavaScriptEngineSwitcher.Vroom;
14+
using JavaScriptEngineSwitcher.Yantra;
15+
16+
var builder = WebApplication.CreateBuilder(new WebApplicationOptions() {
17+
WebRootPath = Path.Combine(
18+
Directory.GetCurrentDirectory(),
19+
"../JavaScriptEngineSwitcher.Sample.AspNetCore.ClientSideAssets/wwwroot"
20+
)
21+
});
22+
var env = builder.Environment;
23+
var configuration = new ConfigurationBuilder()
24+
.SetBasePath(env.ContentRootPath)
25+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
26+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
27+
.AddEnvironmentVariables()
28+
.Build()
29+
;
30+
31+
#region Configure services
32+
33+
IServiceCollection services = builder.Services;
34+
35+
services.AddSingleton(configuration);
36+
37+
// Add Jering Node.js service to the services container.
38+
services.AddNodeJS();
39+
40+
// Add JavaScriptEngineSwitcher services to the services container.
41+
services.AddJsEngineSwitcher(options =>
42+
{
43+
options.AllowCurrentProperty = false;
44+
options.DefaultEngineName = ChakraCoreJsEngine.EngineName;
45+
})
46+
.AddChakraCore()
47+
.AddJint()
48+
.AddJurassic()
49+
.AddMsie(options =>
50+
{
51+
options.EngineMode = JsEngineMode.ChakraIeJsRt;
52+
})
53+
.AddNiL()
54+
.AddNode(services)
55+
.AddV8()
56+
.AddVroom()
57+
.AddYantra()
58+
;
59+
60+
services.Configure<MvcOptions>(options =>
61+
{
62+
options.CacheProfiles.Add("CacheCompressedContent5Minutes",
63+
new CacheProfile
64+
{
65+
NoStore = builder.Environment.IsDevelopment(),
66+
Duration = 300,
67+
Location = ResponseCacheLocation.Client,
68+
VaryByHeader = "Accept-Encoding"
69+
}
70+
);
71+
});
72+
73+
// Add framework services.
74+
services.AddControllersWithViews();
75+
76+
// Add JavaScriptEngineSwitcher sample services to the services container.
77+
services.AddSingleton<JsEvaluationService>();
78+
79+
#endregion
80+
81+
#region Configure the HTTP request pipeline
82+
83+
var app = builder.Build();
84+
85+
if (app.Environment.IsDevelopment())
86+
{
87+
app.UseDeveloperExceptionPage();
88+
}
89+
else
90+
{
91+
app.UseExceptionHandler("/Home/Error");
92+
}
93+
94+
app.UseRouting();
95+
96+
app.MapStaticAssets();
97+
98+
app.MapControllerRoute(
99+
name: "default",
100+
pattern: "{controller=Home}/{action=Index}/{id?}")
101+
.WithStaticAssets();
102+
103+
#endregion
104+
105+
app.Run();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:61316/",
8+
"sslPort": 44396
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"launchBrowser": true,
15+
"environmentVariables": {
16+
"ASPNETCORE_ENVIRONMENT": "Development"
17+
},
18+
"dotnetRunMessages": true,
19+
"applicationUrl": "http://localhost:5169"
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"launchBrowser": true,
24+
"environmentVariables": {
25+
"ASPNETCORE_ENVIRONMENT": "Development"
26+
},
27+
"dotnetRunMessages": true,
28+
"applicationUrl": "https://localhost:7103;http://localhost:5169"
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@{
2+
ViewBag.Title = "Contact";
3+
}
4+
5+
<div class="l-main-content">
6+
<h2>@ViewBag.Title</h2>
7+
@ViewBag.Body
8+
</div>
9+
10+
@section Scripts {
11+
<script>
12+
!function (d, s, id) {
13+
var js, fjs = d.getElementsByTagName(s)[0],
14+
p = /^http:/.test(d.location) ? 'http' : 'https';
15+
if (!d.getElementById(id)) {
16+
js = d.createElement(s);
17+
js.id = id;
18+
js.src = p + '://platform.twitter.com/widgets.js';
19+
fjs.parentNode.insertBefore(js, fjs);
20+
}
21+
}(document, 'script', 'twitter-wjs');
22+
</script>
23+
}

0 commit comments

Comments
 (0)