From d052d4217f71281c2ac582a141af610a29940440 Mon Sep 17 00:00:00 2001 From: nicolaspierre1990 Date: Wed, 19 Dec 2018 14:17:06 +0100 Subject: [PATCH 1/2] temporary fix for #19 --- ...Core.RouteAnalyzer.SampleWebProject.csproj | 9 +++--- .../Controllers/HelloController.cs | 6 +--- .../Pages/About.cshtml.cs | 6 +--- .../Pages/Contact.cshtml.cs | 6 +--- .../Pages/Error.cshtml.cs | 6 +--- .../Pages/Index.cshtml.cs | 7 +--- .../Program.cs | 9 +----- .../Startup.cs | 14 ++++---- .../RouteAnalyzer_MainController.cs | 3 -- AspNetCore.RouteAnalyzer/Extensions.cs | 32 +++++++++++++++---- AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs | 4 +-- AspNetCore.RouteAnalyzer/Inner/Router.cs | 3 -- 12 files changed, 46 insertions(+), 59 deletions(-) diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj b/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj index e3bd8af..62c77e7 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/AspNetCore.RouteAnalyzer.SampleWebProject.csproj @@ -1,10 +1,11 @@ - + - netcoreapp2.0 + netcoreapp2.2 - - + + + diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs index def3243..20019b1 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Controllers/HelloController.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; namespace AspNetCore.RouteAnalyzer.SampleWebProject.Controllers { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/About.cshtml.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/About.cshtml.cs index 23e56eb..7c35cc5 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/About.cshtml.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/About.cshtml.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace AspNetCore.RouteAnalyzer.SampleWebProject.Pages { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Contact.cshtml.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Contact.cshtml.cs index 2ff10ce..bec0608 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Contact.cshtml.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Contact.cshtml.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace AspNetCore.RouteAnalyzer.SampleWebProject.Pages { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Error.cshtml.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Error.cshtml.cs index 3c080cb..2f3b947 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Error.cshtml.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Error.cshtml.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Diagnostics; namespace AspNetCore.RouteAnalyzer.SampleWebProject.Pages { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Index.cshtml.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Index.cshtml.cs index bb2a53b..b656f2e 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Index.cshtml.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Pages/Index.cshtml.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.RazorPages; namespace AspNetCore.RouteAnalyzer.SampleWebProject.Pages { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs index a5892af..261c7cd 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; namespace AspNetCore.RouteAnalyzer.SampleWebProject { diff --git a/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs b/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs index 260d9e4..2c729d2 100644 --- a/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs +++ b/AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System.Diagnostics; @@ -23,7 +22,8 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + services.AddRouting(); services.AddRouteAnalyzer(); } @@ -51,12 +51,14 @@ IRouteAnalyzer routeAnalyzer app.UseMvc(routes => { - routes.MapRouteAnalyzer("/routes"); + //routes.MapRouteAnalyzer("/routes", app.ApplicationServices); routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); + app.MapRouteAnalyzer("/routes"); + // Lifetime events applicationLifetime.ApplicationStarted.Register(OnStarted); applicationLifetime.ApplicationStopping.Register(OnStopping); diff --git a/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs b/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs index 4185f10..7a72047 100644 --- a/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs +++ b/AspNetCore.RouteAnalyzer/Controllers/RouteAnalyzer_MainController.cs @@ -1,7 +1,4 @@ using Microsoft.AspNetCore.Mvc; -using System; -using System.Collections.Generic; -using System.Text; namespace AspNetCore.RouteAnalyzer.Controllers { diff --git a/AspNetCore.RouteAnalyzer/Extensions.cs b/AspNetCore.RouteAnalyzer/Extensions.cs index f5eeca1..c02bf20 100644 --- a/AspNetCore.RouteAnalyzer/Extensions.cs +++ b/AspNetCore.RouteAnalyzer/Extensions.cs @@ -1,6 +1,12 @@ using AspNetCore.RouteAnalyzer.Inner; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using System; +using System.Threading.Tasks; +using System.Linq; +using System.Diagnostics; namespace AspNetCore.RouteAnalyzer { @@ -8,20 +14,34 @@ public static class RouteAnalyzerServiceCollectionExtensions { public static IServiceCollection AddRouteAnalyzer(this IServiceCollection services) { - services.AddSingleton(); + services.AddSingleton(); return services; } } public static class RouteAnalyzerRouteBuilderExtensions { + private static string AspNetCoreRouteAnalyzerRoute = "AspNetCore.RouteAnalyzer.Route"; public static string RouteAnalyzerUrlPath { get; private set; } = ""; - public static IRouteBuilder MapRouteAnalyzer(this IRouteBuilder routes, string routeAnalyzerUrlPath) - { - RouteAnalyzerUrlPath = routeAnalyzerUrlPath; - routes.Routes.Add(new Router(routes.DefaultHandler, routeAnalyzerUrlPath)); - return routes; + public static IApplicationBuilder MapRouteAnalyzer(this IApplicationBuilder app, string routeAnalyzerUrlPath) + { + var aspnetCorErouteHandler = new RouteHandler(context => + { + return Task.Run(() => + { + context.Response.Redirect("RouteAnalyzer_Main/ShowAllRoutes"); + }); + }); + + var routeBuilder = new RouteBuilder(app, aspnetCorErouteHandler); + + routeBuilder.MapRoute(AspNetCoreRouteAnalyzerRoute, routeAnalyzerUrlPath); + + var routes = routeBuilder.Build(); + app.UseRouter(routes); + + return app; } } } diff --git a/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs b/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs index 7480980..97b6ac8 100644 --- a/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs +++ b/AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace AspNetCore.RouteAnalyzer { diff --git a/AspNetCore.RouteAnalyzer/Inner/Router.cs b/AspNetCore.RouteAnalyzer/Inner/Router.cs index 8433d70..5dc949e 100644 --- a/AspNetCore.RouteAnalyzer/Inner/Router.cs +++ b/AspNetCore.RouteAnalyzer/Inner/Router.cs @@ -1,7 +1,4 @@ using Microsoft.AspNetCore.Routing; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace AspNetCore.RouteAnalyzer.Inner From 9944eaf45270838762fe9a75e326337b1c1bbfc3 Mon Sep 17 00:00:00 2001 From: nicolaspierre1990 Date: Wed, 19 Dec 2018 14:19:33 +0100 Subject: [PATCH 2/2] update readme #19 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 20aeb11..2805623 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,13 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) .... app.UseMvc(routes => { - routes.MapRouteAnalyzer("/routes"); // Add routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); + + //This is a temporary workaround solution for endpoint routing of .NET core 2.2 + app.MapRouteAnalyzer("/routes"); } ```