Skip to content

Commit 097faeb

Browse files
Add .NETCore 3 preview support
1 parent 9872ac6 commit 097faeb

File tree

9 files changed

+60
-27
lines changed

9 files changed

+60
-27
lines changed

src/React.AspNet.Middleware/AspNetFileSystem.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
using System.IO;
99
using Microsoft.AspNetCore.Hosting;
1010

11+
#if NETCOREAPP2_0 || NETSTANDARD2_0
12+
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
13+
#endif
14+
1115
namespace React.AspNet
1216
{
1317
/// <summary>
@@ -16,13 +20,13 @@ namespace React.AspNet
1620
/// </summary>
1721
public class AspNetFileSystem : FileSystemBase
1822
{
19-
private readonly IHostingEnvironment _hostingEnv;
23+
private readonly IWebHostEnvironment _hostingEnv;
2024

2125
/// <summary>
2226
/// Initializes a new instance of the <see cref="AspNetFileSystem"/> class.
2327
/// </summary>
2428
/// <param name="hostingEnv">The ASP.NET 5 hosting environment</param>
25-
public AspNetFileSystem(IHostingEnvironment hostingEnv)
29+
public AspNetFileSystem(IWebHostEnvironment hostingEnv)
2630
{
2731
_hostingEnv = hostingEnv;
2832
}

src/React.AspNet.Middleware/BabelFileMiddleware.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
using Microsoft.Extensions.Logging;
1616
using Microsoft.Extensions.Options;
1717

18+
#if NETCOREAPP2_0 || NETSTANDARD2_0
19+
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
20+
#endif
21+
1822
namespace React.AspNet
1923
{
2024
/// <summary>
@@ -23,7 +27,7 @@ namespace React.AspNet
2327
public class BabelFileMiddleware
2428
{
2529
private readonly RequestDelegate _next;
26-
private readonly IHostingEnvironment _hostingEnv;
30+
private readonly IWebHostEnvironment _hostingEnv;
2731
private readonly ILoggerFactory _loggerFactory;
2832
private readonly BabelFileOptions _options;
2933

@@ -34,7 +38,7 @@ public class BabelFileMiddleware
3438
/// <param name="options">The configuration options.</param>
3539
/// <param name="hostingEnv">The hosting environment.</param>
3640
/// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
37-
public BabelFileMiddleware(RequestDelegate next, BabelFileOptions options, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory)
41+
public BabelFileMiddleware(RequestDelegate next, BabelFileOptions options, IWebHostEnvironment hostingEnv, ILoggerFactory loggerFactory)
3842
{
3943
if (next == null)
4044
throw new ArgumentNullException("next");
@@ -93,4 +97,3 @@ private StaticFileMiddleware CreateFileMiddleware(IBabel babel)
9397
}
9498
}
9599
}
96-

src/React.AspNet.Middleware/MemoryFileCacheCore.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
using Microsoft.AspNetCore.Hosting;
1212
using Microsoft.Extensions.FileProviders;
1313

14+
#if NETCOREAPP2_0 || NETSTANDARD2_0
15+
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
16+
#endif
17+
1418
namespace React.AspNet
1519
{
1620
/// <summary>
@@ -19,14 +23,14 @@ namespace React.AspNet
1923
public class MemoryFileCacheCore : ICache
2024
{
2125
private readonly IMemoryCache _cache;
22-
private readonly IHostingEnvironment _hostingEnv;
26+
private readonly IWebHostEnvironment _hostingEnv;
2327

2428
/// <summary>
2529
/// Initializes a new instance of the <see cref="MemoryFileCacheCore" /> class.
2630
/// </summary>
2731
/// <param name="cache">The cache to use</param>
2832
/// <param name="hostingEnv">The ASP.NET hosting environment.</param>
29-
public MemoryFileCacheCore(IMemoryCache cache, IHostingEnvironment hostingEnv)
33+
public MemoryFileCacheCore(IMemoryCache cache, IWebHostEnvironment hostingEnv)
3034
{
3135
_cache = cache;
3236
_hostingEnv = hostingEnv;
@@ -52,7 +56,7 @@ public MemoryFileCacheCore(IMemoryCache cache, IHostingEnvironment hostingEnv)
5256
/// <param name="key">The cache key</param>
5357
/// <param name="data">Data to cache</param>
5458
/// <param name="slidingExpiration">
55-
/// Sliding expiration, if cache key is not accessed in this time period it will
59+
/// Sliding expiration, if cache key is not accessed in this time period it will
5660
/// automatically be removed from the cache
5761
/// </param>
5862
/// <param name="cacheDependencyFiles">

src/React.AspNet.Middleware/React.AspNet.Middleware.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Copyright>Copyright 2014-Present Facebook, Inc</Copyright>
66
<AssemblyTitle>ReactJS.NET - Babel middleware for ASP.NET Core</AssemblyTitle>
77
<Authors>Daniel Lo Nigro</Authors>
8-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
8+
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<AssemblyName>React.AspNet.Middleware</AssemblyName>
1111
<AssemblyOriginatorKeyFile>../key.snk</AssemblyOriginatorKeyFile>
@@ -30,14 +30,18 @@
3030
<ProjectReference Include="..\React.Core\React.Core.csproj" />
3131
</ItemGroup>
3232

33-
<ItemGroup>
33+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
3434
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" />
3535
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
3636
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
3737
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.2.0" />
3838
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.2.0" />
3939
</ItemGroup>
4040

41+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
42+
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.0.0-preview3-19153-02" />
43+
</ItemGroup>
44+
4145
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
4246
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
4347
</PropertyGroup>

src/React.AspNet.Middleware/ReactBuilderExtensions.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
using Microsoft.Extensions.Caching.Memory;
1919
#endif
2020

21+
#if NETCOREAPP2_0 || NETSTANDARD2_0
22+
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
23+
#endif
24+
2125
namespace React.AspNet
2226
{
2327
/// <summary>
@@ -83,7 +87,7 @@ TinyIoCContainer.RegisterOptions registerOptions
8387
/// <param name="services">ASP.NET dependency injection container</param>
8488
private static void RegisterAspNetServices(TinyIoCContainer container, IServiceProvider services)
8589
{
86-
container.Register(services.GetRequiredService<IHostingEnvironment>());
90+
container.Register(services.GetRequiredService<IWebHostEnvironment>());
8791
#if !NET451
8892
container.Register(services.GetRequiredService<IMemoryCache>());
8993
#endif

src/React.AspNet/React.AspNet.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Copyright>Copyright 2014-Present Facebook, Inc</Copyright>
66
<AssemblyTitle>ReactJS.NET (ASP.NET Core MVC)</AssemblyTitle>
77
<Authors>Daniel Lo Nigro</Authors>
8-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
8+
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<AssemblyName>React.AspNet</AssemblyName>
1111
<AssemblyOriginatorKeyFile>../key.snk</AssemblyOriginatorKeyFile>
@@ -30,10 +30,14 @@
3030
<ProjectReference Include="..\React.Core\React.Core.csproj" />
3131
</ItemGroup>
3232

33-
<ItemGroup>
33+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
3434
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.0.0" />
3535
</ItemGroup>
3636

37+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
38+
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.0.0-preview3-19153-02" />
39+
</ItemGroup>
40+
3741
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3842
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
3943
</PropertyGroup>

src/React.Router/React.Router.csproj

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Copyright>Copyright 2014-Present Facebook, Inc</Copyright>
66
<AssemblyTitle>ReactJS.NET Router</AssemblyTitle>
77
<Authors>Daniel Lo Nigro, Gunnar Már Óttarsson</Authors>
8-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
8+
<TargetFrameworks>netstandard2.0;netcoreapp3.0</TargetFrameworks>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<AssemblyName>React.Router</AssemblyName>
1111
<AssemblyOriginatorKeyFile>../key.snk</AssemblyOriginatorKeyFile>
@@ -24,11 +24,15 @@
2424
<Compile Include="..\SharedAssemblyVersionInfo.cs" />
2525
</ItemGroup>
2626

27-
<ItemGroup>
27+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
2828
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.0.0" />
2929
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.0.0" />
3030
</ItemGroup>
3131

32+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.0' ">
33+
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="3.0.0-preview3-19153-02" />
34+
</ItemGroup>
35+
3236
<ItemGroup>
3337
<ProjectReference Include="..\React.AspNet\React.AspNet.csproj" />
3438
<ProjectReference Include="..\React.Core\React.Core.csproj" />

src/React.Sample.Webpack.CoreMvc/React.Sample.Webpack.CoreMvc.csproj

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.1</TargetFramework>
3+
<TargetFrameworks>netcoreapp2.2;netcoreapp3.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<Folder Include="wwwroot\" />
77
</ItemGroup>
8+
9+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.2' ">
10+
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
11+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
12+
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
14+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
15+
</ItemGroup>
16+
817
<ItemGroup>
918
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore" Version="3.0.1" />
1019
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" Version="3.0.1" />
1120
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="3.0.1" />
1221
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x86" Version="3.0.1" />
1322
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" Version="3.0.1" />
1423
<PackageReference Include="JavaScriptEngineSwitcher.Extensions.MsDependencyInjection" Version="3.0.0" />
15-
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
16-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
17-
<PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0" />
18-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
19-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
2024
</ItemGroup>
2125
<ItemGroup>
2226
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />

src/React.Sample.Webpack.CoreMvc/Startup.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@ public void ConfigureServices(IServiceCollection services)
3535
}
3636

3737
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
38-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
38+
public void Configure(IApplicationBuilder app)
3939
{
40-
if (env.IsDevelopment())
41-
{
42-
app.UseDeveloperExceptionPage();
43-
}
44-
4540
// Initialise ReactJS.NET. Must be before static files.
4641
app.UseReact(config =>
4742
{
@@ -57,11 +52,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
5752

5853
app.UseStaticFiles();
5954

55+
#if NETCOREAPP3_0
56+
app.UseEndpoints(endpoints =>
57+
{
58+
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
59+
});
60+
#else
6061
app.UseMvc(routes =>
6162
{
6263
routes.MapRoute("default", "{path?}", new { controller = "Home", action = "Index" });
6364
routes.MapRoute("comments", "comments/page-{page}", new { controller = "Home", action = "Comments" });
6465
});
66+
#endif
6567
}
6668
}
6769
}

0 commit comments

Comments
 (0)