-
Notifications
You must be signed in to change notification settings - Fork 920
Description
There are really two issues:
1.) The following code in ReactConfig.cs will throw an exception on GetObject():
var container = AssemblyRegistration.Container;
container.Register<IReactEnvironment, ReactEnvironment>()
.AsPerRequestSingleton();
This can be run only in places where HttpContext.Current is defined, because re-registering a class with AsPerRequestSingleton checks the items in the current HttpContext (I believe to remove it). This could be fixed with an if (null != HttpContext.Current) { /* do things */ }
2.) Even when registering a new ReactEnvironment
successfully getting JSX files appears to break. A bare minimum test case I have is this: Follow ReactJS.Net tutorial and have a solution with that set up:
Create a new class:
using React;
namespace ReactDotNetExample
{
public class CustomReactEnvironment : ReactEnvironment
{
public CustomReactEnvironment(
IJavaScriptEngineFactory engineFactory,
IReactSiteConfiguration config,
ICache cache,
IFileSystem fileSystem,
IFileCacheHash fileCacheHash
) : base(engineFactory, config, cache, fileSystem, fileCacheHash)
{ }
}
}
Add the following to the HomeController static constructor (HttpContext.Current will be defined here):
var container = AssemblyRegistration.Container;
container.Register<IReactEnvironment, CustomReactEnvironment>()
.AsPerRequestSingleton();
Grabbing .jsx files will now fail even though CustomReactEnvironment and ReactEnvironment are functionally identical (500 error in browser). Adding the following line:
var container = AssemblyRegistration.Container;
container.Register<IReactEnvironment, CustomReactEnvironment>()
.AsPerRequestSingleton();
container.Register<IReactEnvironment, ReactEnvironment>()
.AsPerRequestSingleton();
Works, so the problem is somehow the CustomReactEnvironment class.
For what it's worth, I was trying to see if not disposing/deleting JS Engines per request would speed up server side rendering time, but I couldn't get it to work with a custom environment at all.