Skip to content

Commit 8e13f39

Browse files
committed
Tweaks to get sample site running in .NET Core
1 parent 89bc9cb commit 8e13f39

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

src/React.AspNet/MemoryFileCacheCore.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Collections.Generic;
1313
using Microsoft.Extensions.Caching.Memory;
1414
using System.Linq;
15+
using Microsoft.AspNetCore.Hosting;
1516
using Microsoft.Extensions.FileProviders;
1617

1718
namespace React.AspNet
@@ -28,11 +29,11 @@ public class MemoryFileCacheCore : ICache
2829
/// Initializes a new instance of the <see cref="MemoryFileCacheCore" /> class.
2930
/// </summary>
3031
/// <param name="cache">The cache to use</param>
31-
/// <param name="fileProvider">The file provider.</param>
32-
public MemoryFileCacheCore(IMemoryCache cache, IFileProvider fileProvider)
32+
/// <param name="hostingEnv">The ASP.NET hosting environment.</param>
33+
public MemoryFileCacheCore(IMemoryCache cache, IHostingEnvironment hostingEnv)
3334
{
3435
_cache = cache;
35-
_fileProvider = fileProvider;
36+
_fileProvider = hostingEnv.ContentRootFileProvider;
3637
}
3738

3839
/// <summary>

src/React.AspNet/ReactBuilderExtensions.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
using Microsoft.AspNetCore.Builder;
1212
using Microsoft.AspNetCore.Hosting;
1313
using Microsoft.AspNetCore.Http;
14-
using Microsoft.Extensions.PlatformAbstractions;
1514
using React.Exceptions;
1615
using React.TinyIoC;
1716
using Microsoft.Extensions.DependencyInjection;
17+
#if !NET451
18+
using Microsoft.Extensions.Caching.Memory;
19+
#endif
1820

1921
namespace React.AspNet
2022
{
@@ -38,7 +40,7 @@ public static IApplicationBuilder UseReact(
3840
{
3941
EnsureServicesRegistered(app);
4042

41-
React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IHostingEnvironment>());
43+
RegisterAspNetServices(React.AssemblyRegistration.Container, app.ApplicationServices);
4244

4345
Initializer.Initialize(registerOptions => AsPerRequestSingleton(
4446
app.ApplicationServices.GetService<IHttpContextAccessor>(),
@@ -82,5 +84,19 @@ private static void EnsureServicesRegistered(IApplicationBuilder app)
8284
throw new ReactNotInitialisedException("Please call app.AddReact() before app.UseReact().");
8385
}
8486
}
87+
88+
/// <summary>
89+
/// Registers required ASP.NET services in ReactJS.NET's TinyIoC container. This is used
90+
/// for ASP.NET services that are required by ReactJS.NET.
91+
/// </summary>
92+
/// <param name="container">ReactJS.NET dependency injection container</param>
93+
/// <param name="services">ASP.NET dependency injection container</param>
94+
private static void RegisterAspNetServices(TinyIoCContainer container, IServiceProvider services)
95+
{
96+
container.Register(services.GetRequiredService<IHostingEnvironment>());
97+
#if !NET451
98+
container.Register(services.GetRequiredService<IMemoryCache>());
99+
#endif
100+
}
85101
}
86102
}

src/React.Core/JavaScriptEngineFactory.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using JavaScriptEngineSwitcher.Msie;
99
#if NET40
1010
using JavaScriptEngineSwitcher.V8;
11+
#else
12+
using JavaScriptEngineSwitcher.ChakraCore;
1113
#endif
1214
using JSPool;
1315
using React.Exceptions;
@@ -367,15 +369,13 @@ private static void EnsureJsEnginesRegistered(JsEngineSwitcher jsEngineSwitcher,
367369
#if NET40
368370
jsEngineSwitcher.EngineFactories.AddV8();
369371
#endif
372+
jsEngineSwitcher.EngineFactories.Add(new VroomJsEngine.Factory());
370373
if (allowMsie)
371374
{
372375
jsEngineSwitcher.EngineFactories.AddMsie();
373376
}
374-
#if NET40 || NETSTANDARD1_6
375-
if (JavaScriptEngineUtils.EnvironmentSupportsVroomJs())
376-
{
377-
jsEngineSwitcher.EngineFactories.Add(new VroomJsEngine.Factory());
378-
}
377+
#if !NET40
378+
jsEngineSwitcher.EngineFactories.AddChakraCore();
379379
#endif
380380
}
381381
}

src/React.Sample.ConsoleApp/project.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.6.0-*",
2+
"version": "3.0.0-*",
33
"title": "ReactJS.NET Console Sample",
44
"authors": [ "Daniel Lo Nigro" ],
55
"copyright": "Copyright 2014-Present Facebook, Inc",
@@ -20,6 +20,14 @@
2020
},
2121

2222
"frameworks": {
23-
"net40": {}
23+
"net40": {},
24+
"netcoreapp1.0": {
25+
"dependencies": {
26+
"Microsoft.NETCore.App": {
27+
"type": "platform",
28+
"version": "1.0.0"
29+
}
30+
}
31+
}
2432
}
2533
}

src/React.Sample.Mvc6/project.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"React.AspNet": {
2020
"target": "project"
21-
},
22-
"JavaScriptEngineSwitcher.V8": "2.0.0"
21+
}
2322
},
2423

2524
"tools": {
@@ -30,14 +29,33 @@
3029
},
3130

3231
"frameworks": {
33-
"net451": { }
32+
"net451": {
33+
"dependencies": {
34+
"JavaScriptEngineSwitcher.V8": "2.0.0"
35+
}
36+
},
37+
"netcoreapp1.0": {
38+
"dependencies": {
39+
"Microsoft.NETCore.App": {
40+
"version": "1.0.0",
41+
"type": "platform"
42+
},
43+
"VroomJs": "1.2.3"
44+
}
45+
}
3446
},
3547

3648
"buildOptions": {
3749
"emitEntryPoint": true,
3850
"preserveCompilationContext": true
3951
},
4052

53+
"runtimeOptions": {
54+
"configProperties": {
55+
"System.GC.Server": true
56+
}
57+
},
58+
4159
"publishOptions": {
4260
"include": [
4361
"wwwroot",

0 commit comments

Comments
 (0)