|
1 | | -using System; |
2 | | -using JavaScriptEngineSwitcher.Core; |
3 | | -using JavaScriptEngineSwitcher.Msie; |
4 | | -using Microsoft.AspNetCore.Builder; |
5 | | -using Microsoft.AspNetCore.Hosting; |
6 | | -using Microsoft.AspNetCore.Http; |
7 | | -using Microsoft.Extensions.Configuration; |
8 | | -using Microsoft.Extensions.DependencyInjection; |
9 | | -using React.AspNet; |
10 | | - |
11 | | -namespace React.Sample.Router.CoreMvc |
12 | | -{ |
13 | | - public class Startup |
14 | | - { |
15 | | - public Startup(IConfiguration configuration) |
16 | | - { |
17 | | - Configuration = configuration; |
18 | | - } |
19 | | - |
20 | | - public IConfiguration Configuration { get; } |
21 | | - |
22 | | - // This method gets called by the runtime. Use this method to add services to the container. |
23 | | - public IServiceProvider ConfigureServices(IServiceCollection services) |
24 | | - { |
25 | | - services.AddMvc(); |
26 | | - services.AddReact(); |
27 | | - services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
28 | | - |
29 | | - // Build the intermediate service provider then return it |
30 | | - return services.BuildServiceProvider(); |
31 | | - } |
32 | | - |
33 | | - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
34 | | - public void Configure(IApplicationBuilder app, IHostingEnvironment env) |
35 | | - { |
36 | | - if (env.IsDevelopment()) |
37 | | - { |
38 | | - app.UseDeveloperExceptionPage(); |
39 | | - } |
40 | | - |
41 | | - app.UseStaticFiles(); |
42 | | - |
43 | | - // Initialise ReactJS.NET. Must be before static files. |
44 | | - app.UseReact(config => |
45 | | - { |
46 | | - config |
47 | | - .SetReuseJavaScriptEngines(true) |
48 | | - .SetLoadBabel(false) |
49 | | - .SetLoadReact(false) |
50 | | - .AddScriptWithoutTransform("~/components-bundle.generated.js"); |
51 | | - }); |
52 | | - |
53 | | - app.UseMvc(routes => |
54 | | - { |
55 | | - routes.MapRoute("default", "{path?}", new { controller = "Home", action = "Index" }); |
56 | | - }); |
57 | | - } |
58 | | - } |
59 | | -} |
| 1 | +using System; |
| 2 | +using JavaScriptEngineSwitcher.Core; |
| 3 | +using JavaScriptEngineSwitcher.Msie; |
| 4 | +using Microsoft.AspNetCore.Builder; |
| 5 | +using Microsoft.AspNetCore.Hosting; |
| 6 | +using Microsoft.AspNetCore.Http; |
| 7 | +using Microsoft.Extensions.Configuration; |
| 8 | +using Microsoft.Extensions.DependencyInjection; |
| 9 | +using React.AspNet; |
| 10 | + |
| 11 | +namespace React.Sample.Router.CoreMvc |
| 12 | +{ |
| 13 | + public class Startup |
| 14 | + { |
| 15 | + public Startup(IConfiguration configuration) |
| 16 | + { |
| 17 | + Configuration = configuration; |
| 18 | + } |
| 19 | + |
| 20 | + public IConfiguration Configuration { get; } |
| 21 | + |
| 22 | + // This method gets called by the runtime. Use this method to add services to the container. |
| 23 | + public IServiceProvider ConfigureServices(IServiceCollection services) |
| 24 | + { |
| 25 | + services.AddMvc(); |
| 26 | + services.AddReact(); |
| 27 | + services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); |
| 28 | + |
| 29 | + // Build the intermediate service provider then return it |
| 30 | + return services.BuildServiceProvider(); |
| 31 | + } |
| 32 | + |
| 33 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 34 | + public void Configure(IApplicationBuilder app, IHostingEnvironment env) |
| 35 | + { |
| 36 | + if (env.IsDevelopment()) |
| 37 | + { |
| 38 | + app.UseDeveloperExceptionPage(); |
| 39 | + } |
| 40 | + |
| 41 | + app.UseStaticFiles(); |
| 42 | + |
| 43 | + // Initialise ReactJS.NET. Must be before static files. |
| 44 | + app.UseReact(config => |
| 45 | + { |
| 46 | + config |
| 47 | + .SetReuseJavaScriptEngines(true) |
| 48 | + .SetLoadBabel(false) |
| 49 | + .SetLoadReact(false) |
| 50 | + .AddScriptWithoutTransform("~/components-bundle.generated.js"); |
| 51 | + }); |
| 52 | + |
| 53 | + app.UseMvc(routes => |
| 54 | + { |
| 55 | + routes.MapRoute("default", "{path?}", new { controller = "Home", action = "Index" }); |
| 56 | + }); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments