|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
4 | 4 | using System.Threading.Tasks; |
| 5 | +using JavaScriptEngineSwitcher.ChakraCore; |
| 6 | +using JavaScriptEngineSwitcher.Extensions.MsDependencyInjection; |
5 | 7 | using Microsoft.AspNetCore.Builder; |
6 | 8 | using Microsoft.AspNetCore.Hosting; |
7 | 9 | using Microsoft.AspNetCore.Http; |
|
14 | 16 |
|
15 | 17 | namespace ReactDemo |
16 | 18 | { |
17 | | - public class Startup |
18 | | - { |
19 | | - public Startup(IHostingEnvironment env) |
20 | | - { |
21 | | - var builder = new ConfigurationBuilder() |
22 | | - .SetBasePath(env.ContentRootPath) |
23 | | - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
24 | | - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) |
25 | | - .AddEnvironmentVariables(); |
26 | | - Configuration = builder.Build(); |
27 | | - } |
| 19 | + public class Startup |
| 20 | + { |
| 21 | + public Startup(IHostingEnvironment env) |
| 22 | + { |
| 23 | + var builder = new ConfigurationBuilder() |
| 24 | + .SetBasePath(env.ContentRootPath) |
| 25 | + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
| 26 | + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) |
| 27 | + .AddEnvironmentVariables(); |
| 28 | + Configuration = builder.Build(); |
| 29 | + } |
28 | 30 |
|
29 | | - public IConfigurationRoot Configuration { get; } |
| 31 | + public IConfigurationRoot Configuration { get; } |
| 32 | + |
| 33 | + // This method gets called by the runtime. Use this method to add services to the container. |
| 34 | + public void ConfigureServices(IServiceCollection services) |
| 35 | + { |
| 36 | + services.AddJsEngineSwitcher(options => options.DefaultEngineName = ChakraCoreJsEngine.EngineName) |
| 37 | + .AddChakraCore(); |
30 | 38 |
|
31 | | - // This method gets called by the runtime. Use this method to add services to the container. |
32 | | - public void ConfigureServices(IServiceCollection services) |
33 | | - { |
34 | 39 | services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
35 | 40 | services.AddReact(); |
36 | | - // Add framework services. |
37 | | - services.AddMvc(); |
38 | | - } |
| 41 | + // Add framework services. |
| 42 | + services.AddMvc(); |
| 43 | + } |
39 | 44 |
|
40 | | - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
41 | | - public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
42 | | - { |
43 | | - loggerFactory.AddConsole(Configuration.GetSection("Logging")); |
44 | | - loggerFactory.AddDebug(); |
| 45 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 46 | + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) |
| 47 | + { |
| 48 | + loggerFactory.AddConsole(Configuration.GetSection("Logging")); |
| 49 | + loggerFactory.AddDebug(); |
45 | 50 |
|
46 | | - if (env.IsDevelopment()) |
47 | | - { |
48 | | - app.UseDeveloperExceptionPage(); |
49 | | - app.UseBrowserLink(); |
50 | | - } |
51 | | - else |
52 | | - { |
53 | | - app.UseExceptionHandler("/Home/Error"); |
54 | | - } |
| 51 | + if (env.IsDevelopment()) |
| 52 | + { |
| 53 | + app.UseDeveloperExceptionPage(); |
| 54 | + app.UseBrowserLink(); |
| 55 | + } |
| 56 | + else |
| 57 | + { |
| 58 | + app.UseExceptionHandler("/Home/Error"); |
| 59 | + } |
55 | 60 |
|
56 | 61 | // Initialise ReactJS.NET. Must be before static files. |
57 | 62 | app.UseReact(config => |
@@ -80,12 +85,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF |
80 | 85 |
|
81 | 86 | app.UseStaticFiles(); |
82 | 87 |
|
83 | | - app.UseMvc(routes => |
84 | | - { |
85 | | - routes.MapRoute( |
86 | | - name: "default", |
87 | | - template: "{controller=Home}/{action=Index}/{id?}"); |
88 | | - }); |
89 | | - } |
90 | | - } |
| 88 | + app.UseMvc(routes => |
| 89 | + { |
| 90 | + routes.MapRoute( |
| 91 | + name: "default", |
| 92 | + template: "{controller=Home}/{action=Index}/{id?}"); |
| 93 | + }); |
| 94 | + } |
| 95 | + } |
91 | 96 | } |
0 commit comments