Skip to content
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

Fix for Endpoint routing #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
9 changes: 1 addition & 8 deletions AspNetCore.RouteAnalyzer.SampleWebProject/Program.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
14 changes: 8 additions & 6 deletions AspNetCore.RouteAnalyzer.SampleWebProject/Startup.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;

namespace AspNetCore.RouteAnalyzer.Controllers
{
Expand Down
32 changes: 26 additions & 6 deletions AspNetCore.RouteAnalyzer/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
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
{
public static class RouteAnalyzerServiceCollectionExtensions
{
public static IServiceCollection AddRouteAnalyzer(this IServiceCollection services)
{
services.AddSingleton<IRouteAnalyzer, RouteAnalyzer.Inner.RouteAnalyzerImpl>();
services.AddSingleton<IRouteAnalyzer, RouteAnalyzerImpl>();
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;
}
}
}
4 changes: 1 addition & 3 deletions AspNetCore.RouteAnalyzer/IRouteAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;

namespace AspNetCore.RouteAnalyzer
{
Expand Down
3 changes: 0 additions & 3 deletions AspNetCore.RouteAnalyzer/Inner/Router.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
```

Expand Down