Skip to content

Getting started tutorial documentation #447

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

Closed
tachyon1337 opened this issue Oct 22, 2017 · 2 comments
Closed

Getting started tutorial documentation #447

tachyon1337 opened this issue Oct 22, 2017 · 2 comments

Comments

@tachyon1337
Copy link

The documentation is out of date as it applies to Core 2.0. And for development environments other than windows, additional steps are likely necessary to get a default aspnet core template up and running using React.NET.

Using Visual Studio for Mac on macOS sierra, I had to do the following to get the tutorial up and running.

(1) Install the following nuget package
Install-Package JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64

(2) Fetch the latest Chakra runtime from github

https://github.com/Microsoft/ChakraCore/releases

and copy that over the old runtime installed by the nuget package

.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.6/runtimes/osx-x64/native/libChakraCore.dylib

(3) add the following using statements to Startup.cs

using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.ChakraCore;

(4) Modify the return type of ConfigureServices

public IServiceProvider ConfigureServices(IServiceCollection services)
{
      services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
      services.AddReact();
      services.AddMvc();
      return services.BuildServiceProvider();
}

(5) Switch out the javascript engine in Configure

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
      if (env.IsDevelopment())
      {
            app.UseDeveloperExceptionPage();
      }
      else
      {
             app.UseExceptionHandler("/Home/Error");
       }
      var engineSwitcher = JsEngineSwitcher.Instance;
      engineSwitcher.DefaultEngineName = ChakraCoreJsEngine.EngineName;
      engineSwitcher.EngineFactories
                       .AddChakraCore();
            
      app.UseReact(config=>{  
      });
      app.UseStaticFiles();
      app.UseMvc(routes =>
      {
            routes.MapRoute(
                 name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
       });

}

Then the tutorial worked as expected. Posting the above might save someone else a number of hours scouring the issue threads.

@Taritsyn
Copy link
Contributor

(2) Fetch the latest Chakra runtime from github

https://github.com/Microsoft/ChakraCore/releases

and copy that over the old runtime installed by the nuget package

.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.6/runtimes/osx-x64/native/libChakraCore.dylib

This problem is solved in version 3.0.0 Alpha 6. There is even a discussion on this topic.

 var engineSwitcher = JsEngineSwitcher.Instance;
 engineSwitcher.DefaultEngineName = ChakraCoreJsEngine.EngineName;
 engineSwitcher.EngineFactories
                  .AddChakraCore();

If you install the JavaScriptEngineSwitcher.Extensions.MsDependencyInjection package, you can make this code better:

services.AddJsEngineSwitcher(options =>
	options.DefaultEngineName = ChakraCoreJsEngine.EngineName
)
	.AddChakraCore()
	;

For more information, see in the “Registration of JS engines > ASP.NET Core 1.X” section of documentation.

@dustinsoftware
Copy link
Member

Closing issues older than a year, please re-open if you think this is still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants