diff --git a/Q102939/Q102939.csproj b/Q102939/Q102939.csproj index 4f2f572..47ef911 100644 --- a/Q102939/Q102939.csproj +++ b/Q102939/Q102939.csproj @@ -9,7 +9,7 @@ - + diff --git a/Q133689/Program.cs b/Q133689/Program.cs new file mode 100644 index 0000000..04eab9f --- /dev/null +++ b/Q133689/Program.cs @@ -0,0 +1,50 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Routing.Patterns; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Moq; + +namespace Q133689 +{ + class Program + { + static async Task Main(string[] args) + { + var requestPath = "/cmt/p/14408628.html"; + + var routeTemplate = "/{blogApp}/{postType}/{idOrSlug}.html"; + var routeHandler = new RouteHandler((context) => null); + + IServiceCollection services = new ServiceCollection(); + services.AddSingleton(NullLoggerFactory.Instance); + services.AddOptions(); + var sp = services.BuildServiceProvider(); + + var routeOptions = sp.GetRequiredService>(); + var inlineConstraintResolver = new DefaultInlineConstraintResolver(routeOptions, sp); + var route = new Route( + routeHandler, + routeTemplate, + defaults: null, + constraints: new RouteValueDictionary(), + dataTokens: null, + inlineConstraintResolver: inlineConstraintResolver); + + var httpContext = new DefaultHttpContext(); + httpContext.Request.Path = new PathString(requestPath); + httpContext.RequestServices = sp; + + var routeContext = new RouteContext(httpContext); + await route.RouteAsync(routeContext); + + Console.WriteLine("blogApp: " + routeContext.RouteData.Values["blogApp"]); + Console.WriteLine("postType:" + routeContext.RouteData.Values["postType"]); + Console.WriteLine("idOrSlug:" + routeContext.RouteData.Values["idOrSlug"]); + } + } +} diff --git a/Q133689/Q133689.csproj b/Q133689/Q133689.csproj new file mode 100644 index 0000000..cfe9f71 --- /dev/null +++ b/Q133689/Q133689.csproj @@ -0,0 +1,17 @@ + + + + Exe + net5.0 + + + + + + + + + + + + diff --git a/Q133689/Q133689.sln b/Q133689/Q133689.sln new file mode 100644 index 0000000..10c39d4 --- /dev/null +++ b/Q133689/Q133689.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31019.35 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Q133689", "Q133689.csproj", "{8D6FAF8C-153A-48C7-BA94-37C3928BA462}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8D6FAF8C-153A-48C7-BA94-37C3928BA462}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8FDB8807-4FBB-4A35-A737-82A5C18B07C4} + EndGlobalSection +EndGlobal