-
Notifications
You must be signed in to change notification settings - Fork 920
Making React.AspNet compatible with ASP.NET Core RC2 #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
24f78ca
aa17057
b566a5a
fa05d2e
e887678
bf07e55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,12 @@ | |
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.AspNet.StaticFiles; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.StaticFiles; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace React.AspNet | ||
{ | ||
|
@@ -73,22 +74,22 @@ public async Task Invoke(HttpContext context) | |
/// <returns></returns> | ||
private StaticFileMiddleware CreateFileMiddleware(IBabel babel) | ||
{ | ||
return new StaticFileMiddleware( | ||
return new StaticFileMiddleware( | ||
_next, | ||
_hostingEnv, | ||
new StaticFileOptions | ||
{ | ||
ContentTypeProvider = _options.StaticFileOptions.ContentTypeProvider, | ||
DefaultContentType = _options.StaticFileOptions.DefaultContentType, | ||
OnPrepareResponse = _options.StaticFileOptions.OnPrepareResponse, | ||
RequestPath = _options.StaticFileOptions.RequestPath, | ||
ServeUnknownFileTypes = _options.StaticFileOptions.ServeUnknownFileTypes, | ||
FileProvider = new BabelFileSystem( | ||
babel, | ||
_options.StaticFileOptions.FileProvider ?? _hostingEnv.WebRootFileProvider, | ||
_options.Extensions | ||
) | ||
}, | ||
Options.Create(new StaticFileOptions | ||
|
||
{ | ||
ContentTypeProvider = _options.StaticFileOptions.ContentTypeProvider, | ||
DefaultContentType = _options.StaticFileOptions.DefaultContentType, | ||
OnPrepareResponse = _options.StaticFileOptions.OnPrepareResponse, | ||
RequestPath = _options.StaticFileOptions.RequestPath, | ||
ServeUnknownFileTypes = _options.StaticFileOptions.ServeUnknownFileTypes, | ||
FileProvider = new BabelFileSystem( | ||
babel, | ||
_options.StaticFileOptions.FileProvider ?? _hostingEnv.WebRootFileProvider, | ||
_options.Extensions | ||
) | ||
}), | ||
_loggerFactory | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
using System; | ||
using System.Collections.Concurrent; | ||
using System.Linq; | ||
using Microsoft.AspNet.Http; | ||
using Microsoft.AspNetCore.Http; | ||
using React.Exceptions; | ||
using React.TinyIoC; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
@@ -43,28 +43,14 @@ public HttpContextLifetimeProvider(IServiceProvider appServiceProvider) | |
/// </summary> | ||
private readonly string _keyName = PREFIX + Guid.NewGuid(); | ||
|
||
/// <summary> | ||
/// Gets the <see cref="HttpContext" /> of the current request. | ||
/// </summary> | ||
private HttpContext HttpContext => | ||
_appServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext; | ||
|
||
/// <summary> | ||
/// Gets the current per-request registrations for the current request. | ||
/// </summary> | ||
private PerRequestRegistrations Registrations | ||
{ | ||
get | ||
{ | ||
var requestServices = HttpContext.RequestServices; | ||
if (requestServices == null) | ||
{ | ||
throw new ReactNotInitialisedException( | ||
"ASP.NET request services have not been initialised correctly. Please " + | ||
"ensure you are calling app.UseRequestServices() before app.UseReact()." | ||
); | ||
} | ||
var registrations = requestServices.GetService<PerRequestRegistrations>(); | ||
var registrations = _appServiceProvider.GetService<PerRequestRegistrations>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was incorrect, it wasn't handling per-request singletons properly and was instead just using a single instance for the entire app. I fixed it in a4992da 👍 |
||
if (registrations == null) | ||
{ | ||
throw new ReactNotInitialisedException( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("React.AspNet")] | ||
[assembly: AssemblyDescription("ReactJS and Babel tools for ASP.NET Core, including ASP.NET Core MVC")] | ||
[assembly: ComVisible(false)] | ||
[assembly: Guid("f0e355fc-a89f-4fd6-b171-1ef03c838a67")] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,33 +4,18 @@ | |
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
|
||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>a7acdb56-5e43-40a6-92c9-2c52228e6074</ProjectGuid> | ||
<ProjectGuid>f0e355fc-a89f-4fd6-b171-1ef03c838a67</ProjectGuid> | ||
|
||
<RootNamespace>React.AspNet</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\bin\$(MSBuildProjectName)\</OutputPath> | ||
</PropertyGroup> | ||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<AssemblyName>React.AspNet</AssemblyName> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\React.Core\React.Core.csproj" /> | ||
</ItemGroup> | ||
<ProjectExtensions> | ||
<VisualStudio> | ||
<UserProperties /> | ||
</VisualStudio> | ||
</ProjectExtensions> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" /> | ||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" /> | ||
</Project> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,8 @@ | |
*/ | ||
|
||
using System; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.PlatformAbstractions; | ||
using React.Exceptions; | ||
using React.TinyIoC; | ||
|
@@ -40,7 +40,6 @@ public static IApplicationBuilder UseReact( | |
// Register IApplicationEnvironment in our dependency injection container | ||
// Ideally this would be in AddReact(IServiceCollection) but we can't | ||
// access IApplicationEnvironment there. | ||
React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IApplicationEnvironment>()); | ||
React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IHostingEnvironment>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the comment too, please. |
||
|
||
Initializer.Initialize(registerOptions => AsPerRequestSingleton(app.ApplicationServices, registerOptions)); | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,43 +1,52 @@ | ||||
{ | ||||
"version": "2.3.0-*", | ||||
"configurations": { | ||||
"Debug": { | ||||
"compilationOptions": { | ||||
"define": [ "DEBUG", "TRACE", "ASPNET5" ] | ||||
} | ||||
}, | ||||
"Release": { | ||||
"compilationOptions": { | ||||
"define": [ "RELEASE", "TRACE", "ASPNET5" ], | ||||
"optimize": true, | ||||
"warningsAsErrors": true | ||||
} | ||||
} | ||||
"version": "2.3.0-*", | ||||
"authors": [ "Daniel Lo Nigro" ], | ||||
"packOptions": { | ||||
"owners": [ "Daniel Lo Nigro" ], | ||||
"licenseUrl": "https://github.com/reactjs/React.NET#licence", | ||||
"iconUrl": "http://facebook.github.io/react/img/logo_og.png", | ||||
"copyright": "Copyright 2014-Present Facebook, Inc", | ||||
"title": "ReactJS.NET (MVC Core)", | ||||
"description": "ReactJS and Babel tools for ASP.NET Core, including ASP.NET MVC Core. Please refer to project site (http://reactjs.net/) for full installation instructions, usage examples and sample code", | ||||
"tags": [ "asp.net", "mvc", "asp", "javascript", "js", "react", "facebook", "reactjs", "vnext" ], | ||||
"projectUrl": "http://reactjs.net/" | ||||
}, | ||||
"configurations": { | ||||
"Debug": { | ||||
"buildOptions": { | ||||
"define": [ "DEBUG", "TRACE", "ASPNET5" ] | ||||
|
#if LEGACYASPNET |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is totally fine, I wonder if it should be done in build.proj
along with all the other NuGet packages, to keep everything consistent.
Thanks for figuring this out, btw :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking exactly the same thing, I'm going to try it on build.proj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this run the equivalent
dotnet
command to ensure RC2 is installed on the build machine?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know it no longer works that way in RC2. There is no equivalent to dnvm in the new toolset. If you have .NET Core RC2 installed already, you can just get the ASP.NET Core packages using NuGet.
That was one of the biggest changes from RC1 to RC2, and it was done in order to make all .NET Core environments consistent with each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like they've got an install script for CI servers (see https://dotnet.github.io/docs/core-concepts/dnx-migration.html). However, their docs for AppVeyor just say "TODO" (https://dotnet.github.io/docs/core-concepts/core-sdk/cli/using-ci-with-cli.html). It's fine to ignore that for now if the AppVeyor build actually works with no changes.