Пример #1
0
 public SitemapController(ISitemapXml sitemapXml, IPersonService personService, IArtistService artistService, ISongService songService, ISpaRouteService spaRouteService)
 {
     this.sitemapXml      = sitemapXml;
     this.personService   = personService;
     this.artistService   = artistService;
     this.songService     = songService;
     this.spaRouteService = spaRouteService;
 }
Пример #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ISpaRouteService currentSpaRoute)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app
            .UseHttpsRedirection()
            .UseHsts()
            .UseStaticFiles()
            .UseSpaStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                spa.UseSpaPrerendering(options =>
                {
                    options.BootModulePath    = $"{spa.Options.SourcePath}/dist/server/main.js";
                    options.BootModuleBuilder = env.IsDevelopment()
                        ? new AngularCliBuilder(npmScript: "build:ssr")
                        : null;
                    options.ExcludeUrls = new[] { "/sockjs-node" };

                    options.SupplyData = (context, data) =>
                    {
                        var route = currentSpaRoute.GetCurrentRoute(context);

                        var personRepository = context.RequestServices.GetRequiredService <IPersonRepository>();

                        switch (route?.Name)
                        {
                        case "person-list":
                            {
                                var people     = personRepository.GetPeople();
                                data["people"] = people;
                            }
                            break;

                        case "person-show":
                        case "person-edit":
                            {
                                var id         = System.Convert.ToInt32(route.Parameters["id"]);
                                var person     = personRepository.GetPerson(id);
                                data["person"] = person;
                            }
                            break;
                        }

                        data.Add("message", "Message from server");
                    };
                });

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISpaRouteService currentSpaRoute)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

#pragma warning disable CS0618 // Type or member is obsolete
                spa.UseSpaPrerendering(options =>
                {
                    options.BootModulePath    = $"{spa.Options.SourcePath}/dist/ClientApp/server/main.js";
                    options.BootModuleBuilder = env.IsDevelopment()
                        ? new AngularCliBuilder(npmScript: "build:ssr")
                        : null;

                    options.ExcludeUrls = new[] { "/sockjs-node" };

                    options.SupplyData = async(context, data) =>
                    {
                        var route = currentSpaRoute.GetCurrentRoute(context);

                        var personService = context.RequestServices.GetRequiredService <IPersonService>();

                        switch (route?.Name)
                        {
                        case "person-list":
                            {
                                var people     = await personService.GetPeople();
                                data["people"] = people;
                            }
                            break;

                        case "person-show":
                        case "person-edit":
                            {
                                var id         = System.Convert.ToInt32(route.Parameters["personid"]);
                                var person     = await personService.GetPerson(id);
                                data["person"] = person;
                            }
                            break;
                        }

                        data.Add("message", "Message from server");
                    };
                });
#pragma warning restore CS0618 // Type or member is obsolete

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
Пример #4
0
 public OpenSearchService(IServiceProvider serviceProvider, ISpaRouteService spaRouteService)
 {
     this.serviceProvider = serviceProvider;
     this.spaRouteService = spaRouteService;
 }
 public PersonController(IPersonRepository personRepository, ISpaRouteService spaRouteService)
 {
     this.personRepository = personRepository;
     this.spaRouteService  = spaRouteService;
 }
 public DemoSpaPrerenderingService(ISpaRouteService spaRouteService, IPersonService personService)
 {
     this.spaRouteService = spaRouteService;
     this.personService   = personService;
 }