diff --git a/src/Mvc/Directory.Build.targets b/src/Mvc/Directory.Build.targets index 73b97f2807..51a6545f0c 100644 --- a/src/Mvc/Directory.Build.targets +++ b/src/Mvc/Directory.Build.targets @@ -1,9 +1,7 @@ $(MicrosoftNETCoreApp21PackageVersion) - $(MicrosoftNETCoreApp22PackageVersion) + $(MicrosoftNETCoreAppPackageVersion) $(NETStandardLibrary20PackageVersion) - - 99.9 diff --git a/src/Mvc/Mvc.NoFun.sln b/src/Mvc/Mvc.NoFun.sln index d67abd6f60..0a8840d257 100644 --- a/src/Mvc/Mvc.NoFun.sln +++ b/src/Mvc/Mvc.NoFun.sln @@ -28,10 +28,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Co EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Test", "test\Microsoft.AspNetCore.Mvc.Test\Microsoft.AspNetCore.Mvc.Test.csproj", "{5F945B82-FE5F-425C-956C-8BC2F2020254}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.WebApiCompatShim", "src\Microsoft.AspNetCore.Mvc.WebApiCompatShim\Microsoft.AspNetCore.Mvc.WebApiCompatShim.csproj", "{23D30B8C-04B1-4577-A604-ED27EA1E4A0E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.WebApiCompatShimTest", "test\Microsoft.AspNetCore.Mvc.WebApiCompatShimTest\Microsoft.AspNetCore.Mvc.WebApiCompatShimTest.csproj", "{5DE8E4D9-AACD-4B5F-819F-F091383FB996}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.TagHelpers", "src\Microsoft.AspNetCore.Mvc.TagHelpers\Microsoft.AspNetCore.Mvc.TagHelpers.csproj", "{B2347320-308E-4D2B-AEC8-005DFA68B0C9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.TagHelpers.Test", "test\Microsoft.AspNetCore.Mvc.TagHelpers.Test\Microsoft.AspNetCore.Mvc.TagHelpers.Test.csproj", "{860119ED-3DB1-424D-8D0A-30132A8A7D96}" @@ -193,26 +189,6 @@ Global {5F945B82-FE5F-425C-956C-8BC2F2020254}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {5F945B82-FE5F-425C-956C-8BC2F2020254}.Release|Mixed Platforms.Build.0 = Release|Any CPU {5F945B82-FE5F-425C-956C-8BC2F2020254}.Release|x86.ActiveCfg = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|x86.ActiveCfg = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Any CPU.Build.0 = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|x86.ActiveCfg = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|x86.ActiveCfg = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Any CPU.Build.0 = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|x86.ActiveCfg = Release|Any CPU {B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -628,8 +604,6 @@ Global {3F6E355E-4869-41D9-943B-D54771221A7F} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {A8AA326E-8EE8-4F11-B750-23028E0949D7} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {5F945B82-FE5F-425C-956C-8BC2F2020254} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E} - {5DE8E4D9-AACD-4B5F-819F-F091383FB996} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {B2347320-308E-4D2B-AEC8-005DFA68B0C9} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E} {860119ED-3DB1-424D-8D0A-30132A8A7D96} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {F504357E-C2E1-4818-BA5C-9A2EAC25FEE5} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} diff --git a/src/Mvc/Mvc.sln b/src/Mvc/Mvc.sln index dcd83f09ca..00eabf0c6a 100644 --- a/src/Mvc/Mvc.sln +++ b/src/Mvc/Mvc.sln @@ -53,12 +53,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FilesWebSite", "test\WebSit EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationModelWebSite", "test\WebSites\ApplicationModelWebSite\ApplicationModelWebSite.csproj", "{CAE52CB7-0FAC-4B5B-8251-B0FF837DB657}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.WebApiCompatShim", "src\Microsoft.AspNetCore.Mvc.WebApiCompatShim\Microsoft.AspNetCore.Mvc.WebApiCompatShim.csproj", "{23D30B8C-04B1-4577-A604-ED27EA1E4A0E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApiCompatShimWebSite", "test\WebSites\WebApiCompatShimWebSite\WebApiCompatShimWebSite.csproj", "{B2B7BC91-688E-4C1E-A71F-CE948D958DDF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.WebApiCompatShimTest", "test\Microsoft.AspNetCore.Mvc.WebApiCompatShimTest\Microsoft.AspNetCore.Mvc.WebApiCompatShimTest.csproj", "{5DE8E4D9-AACD-4B5F-819F-F091383FB996}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.TagHelpers", "src\Microsoft.AspNetCore.Mvc.TagHelpers\Microsoft.AspNetCore.Mvc.TagHelpers.csproj", "{B2347320-308E-4D2B-AEC8-005DFA68B0C9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.TagHelpers.Test", "test\Microsoft.AspNetCore.Mvc.TagHelpers.Test\Microsoft.AspNetCore.Mvc.TagHelpers.Test.csproj", "{860119ED-3DB1-424D-8D0A-30132A8A7D96}" @@ -354,36 +348,6 @@ Global {CAE52CB7-0FAC-4B5B-8251-B0FF837DB657}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {CAE52CB7-0FAC-4B5B-8251-B0FF837DB657}.Release|Mixed Platforms.Build.0 = Release|Any CPU {CAE52CB7-0FAC-4B5B-8251-B0FF837DB657}.Release|x86.ActiveCfg = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Debug|x86.ActiveCfg = Debug|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Any CPU.Build.0 = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E}.Release|x86.ActiveCfg = Release|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Debug|x86.ActiveCfg = Debug|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Release|Any CPU.Build.0 = Release|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF}.Release|x86.ActiveCfg = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Debug|x86.ActiveCfg = Debug|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Any CPU.Build.0 = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {5DE8E4D9-AACD-4B5F-819F-F091383FB996}.Release|x86.ActiveCfg = Release|Any CPU {B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Any CPU.Build.0 = Debug|Any CPU {B2347320-308E-4D2B-AEC8-005DFA68B0C9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU @@ -1002,9 +966,6 @@ Global {6DB9B8D0-80F7-4E70-BBB0-0B4C04D79A47} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {0EF9860B-10D7-452F-B0F4-A405B88BEBB3} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} {CAE52CB7-0FAC-4B5B-8251-B0FF837DB657} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} - {23D30B8C-04B1-4577-A604-ED27EA1E4A0E} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E} - {B2B7BC91-688E-4C1E-A71F-CE948D958DDF} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} - {5DE8E4D9-AACD-4B5F-819F-F091383FB996} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {B2347320-308E-4D2B-AEC8-005DFA68B0C9} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E} {860119ED-3DB1-424D-8D0A-30132A8A7D96} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1} {920F8A0E-6F7D-4BBE-84FF-840B89099BE6} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C} diff --git a/src/Mvc/README.md b/src/Mvc/README.md index 775ed6bd0c..babc35f1d9 100644 --- a/src/Mvc/README.md +++ b/src/Mvc/README.md @@ -3,7 +3,7 @@ ASP.NET Core MVC **Note: For ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core), see https://github.com/aspnet/AspNetWebStack** -Travis: [![Travis](https://travis-ci.org/aspnet/Mvc.svg?branch=release/2.2)](https://travis-ci.org/aspnet/Mvc) +Travis: [![Travis](https://travis-ci.org/aspnet/Mvc.svg?branch=master)](https://travis-ci.org/aspnet/Mvc) ASP.NET Core MVC gives you a powerful, patterns-based way to build dynamic websites that enables a clean separation of concerns and gives you full control over markup for enjoyable, agile development. ASP.NET Core MVC includes many features that enable fast, TDD-friendly development for creating sophisticated applications that use the latest web standards. diff --git a/src/Mvc/benchmarkapps/BasicApi/BasicApi.csproj b/src/Mvc/benchmarkapps/BasicApi/BasicApi.csproj index ec6e654069..397424ebfd 100644 --- a/src/Mvc/benchmarkapps/BasicApi/BasicApi.csproj +++ b/src/Mvc/benchmarkapps/BasicApi/BasicApi.csproj @@ -1,7 +1,6 @@  - netcoreapp2.2 - $(TargetFrameworks);net461 + netcoreapp3.0 $(BenchmarksTargetFramework) $(DefineConstants);GENERATE_SQL_SCRIPTS @@ -38,6 +37,6 @@ Use All meta-package and not App to include Microsoft.EntityFrameworkCore.Sqlite. --> - + diff --git a/src/Mvc/benchmarkapps/BasicApi/benchmarks.json b/src/Mvc/benchmarkapps/BasicApi/benchmarks.json index aff5eb280d..c1497d0465 100644 --- a/src/Mvc/benchmarkapps/BasicApi/benchmarks.json +++ b/src/Mvc/benchmarkapps/BasicApi/benchmarks.json @@ -7,7 +7,7 @@ "PresetHeaders": "Json", "ReadyStateText": "Application started.", "Source": { - "BranchOrCommit": "release/2.2", + "BranchOrCommit": "master", "Project": "benchmarkapps/BasicApi/BasicApi.csproj", "Repository": "https://github.com/aspnet/mvc.git" } @@ -19,20 +19,20 @@ }, "BasicApi.GetUsingQueryString": { "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicApi/getWithToken.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicApi/getWithToken.lua" }, "Path": "/pet/findByStatus", "Query": "?status=available" }, "BasicApi.GetUsingRouteValue": { "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicApi/getWithToken.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicApi/getWithToken.lua" }, "Path": "/pet/-1" }, "BasicApi.GetUsingRouteValueWithoutAuthorization": { "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicApi/getWithToken.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicApi/getWithToken.lua" }, "Path": "/pet/anonymous/-1" }, @@ -41,14 +41,14 @@ }, "BasicApi.Post": { "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicApi/postJsonWithToken.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicApi/postJsonWithToken.lua" }, "Path": "/pet" }, "BasicApi.PostWithoutDb": { "Path": "/pet/add-pet", "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicApi/postJsonWithToken.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicApi/postJsonWithToken.lua" } } } diff --git a/src/Mvc/benchmarkapps/BasicViews/BasicViews.csproj b/src/Mvc/benchmarkapps/BasicViews/BasicViews.csproj index 6e62f39598..ba832b8e25 100644 --- a/src/Mvc/benchmarkapps/BasicViews/BasicViews.csproj +++ b/src/Mvc/benchmarkapps/BasicViews/BasicViews.csproj @@ -1,7 +1,6 @@  - netcoreapp2.2 - $(TargetFrameworks);net461 + netcoreapp3.0 $(BenchmarksTargetFramework) $(DefineConstants);GENERATE_SQL_SCRIPTS @@ -38,7 +37,7 @@ Use All meta-package and not App to include Microsoft.EntityFrameworkCore.Sqlite. --> - - + + diff --git a/src/Mvc/benchmarkapps/BasicViews/benchmarks.json b/src/Mvc/benchmarkapps/BasicViews/benchmarks.json index 6a50d9386d..75e77df4c5 100644 --- a/src/Mvc/benchmarkapps/BasicViews/benchmarks.json +++ b/src/Mvc/benchmarkapps/BasicViews/benchmarks.json @@ -7,7 +7,7 @@ "PresetHeaders": "Html", "ReadyStateText": "Application started.", "Source": { - "BranchOrCommit": "release/2.2", + "BranchOrCommit": "master", "Project": "benchmarkapps/BasicViews/BasicViews.csproj", "Repository": "https://github.com/aspnet/mvc.git" } @@ -20,19 +20,19 @@ }, "BasicViews.Post": { "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicViews/postWithToken.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicViews/postWithToken.lua" }, "Path": "/Home/Index" }, "BasicViews.PostIgnoringToken": { "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicViews/postWithToken.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicViews/postWithToken.lua" }, "Path": "/Home/IndexWithoutToken" }, "BasicViews.PostWithoutToken": { "ClientProperties": { - "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/release/2.2/benchmarkapps/BasicViews/post.lua" + "Scripts": "https://raw.githubusercontent.com/aspnet/Mvc/master/benchmarkapps/BasicViews/post.lua" }, "Path": "/Home/IndexWithoutToken" } diff --git a/src/Mvc/benchmarkapps/RazorRendering/RazorRendering.csproj b/src/Mvc/benchmarkapps/RazorRendering/RazorRendering.csproj index dc531b3fdf..c599280493 100644 --- a/src/Mvc/benchmarkapps/RazorRendering/RazorRendering.csproj +++ b/src/Mvc/benchmarkapps/RazorRendering/RazorRendering.csproj @@ -1,6 +1,7 @@  - netcoreapp2.2 + netcoreapp3.0 + $(BenchmarksTargetFramework) @@ -16,8 +17,8 @@ These references are used when running on the Benchmarks Server. --> - - + + diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/HelperExtensions.cs b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/HelperExtensions.cs new file mode 100644 index 0000000000..460ffef86f --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/HelperExtensions.cs @@ -0,0 +1,21 @@ +using System; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc.Razor; + +public static class HelperExtensions +{ + public static Func Helper( + this RazorPageBase page, + Func> helper + ) => p1 => helper(p1)(null); + + public static Func Helper( + this RazorPageBase page, + Func> helper + ) => (p1, p2) => helper(p1, p2)(null); + + public static Func Helper( + this RazorPageBase page, + Func> helper + ) => (p1, p2, p3) => helper(p1, p2, p3)(null); +} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Microsoft.AspNetCore.Mvc.Performance.Views.csproj b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Microsoft.AspNetCore.Mvc.Performance.Views.csproj new file mode 100644 index 0000000000..ad01f2e69e --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Microsoft.AspNetCore.Mvc.Performance.Views.csproj @@ -0,0 +1,18 @@ + + + + netcoreapp3.0 + + false + + <_EnableAllInclusiveRazorSdk>true + 3.0 + MVC-3.0 + + + + + + + + diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/ViewAssemblyMarker.cs b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/ViewAssemblyMarker.cs new file mode 100644 index 0000000000..bf2dfcd02d --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/ViewAssemblyMarker.cs @@ -0,0 +1,6 @@ +namespace Microsoft.AspNetCore.Mvc.Performance +{ + public class ViewAssemblyMarker + { + } +} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelloWorld.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelloWorld.cshtml new file mode 100644 index 0000000000..70c379b63f --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelloWorld.cshtml @@ -0,0 +1 @@ +Hello world \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperDynamic.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperDynamic.cshtml new file mode 100644 index 0000000000..8a476f9847 --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperDynamic.cshtml @@ -0,0 +1,7 @@ +@using System; +@using Microsoft.AspNetCore.Html +@model System.String +@{Func SomeHelper = @@{ +@item +};} +@for (var i = 0; i < 100; i++){@SomeHelper(Model + i.ToString())} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperExtensions.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperExtensions.cshtml new file mode 100644 index 0000000000..583a755d1b --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperExtensions.cshtml @@ -0,0 +1,10 @@ +@using System; +@using Microsoft.AspNetCore.Html +@model System.String +@{ + var SomeHelper = this.Helper((string s) => @@item); +} +@for (var i = 0; i < 100; i++) +{ + @SomeHelper(Model + i.ToString()) +} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialAsync.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialAsync.cshtml new file mode 100644 index 0000000000..d8bc51b756 --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialAsync.cshtml @@ -0,0 +1,7 @@ +@using System; +@using Microsoft.AspNetCore.Html +@model System.String +@for (var i = 0; i < 100; i++) +{ + await Html.RenderPartialAsync("~/Views/HelperPartial_Partial.cshtml", Model + i.ToString()); +} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialSync.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialSync.cshtml new file mode 100644 index 0000000000..cd17862b20 --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialSync.cshtml @@ -0,0 +1,7 @@ +@using System; +@using Microsoft.AspNetCore.Html +@model System.String +@for (var i = 0; i < 100; i++) +{ + Html.RenderPartial("~/Views/HelperPartial_Partial.cshtml", Model + i.ToString()); +} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialTagHelper.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialTagHelper.cshtml new file mode 100644 index 0000000000..dc76d33bf2 --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartialTagHelper.cshtml @@ -0,0 +1,6 @@ +@using System; +@using Microsoft.AspNetCore.Html +@model System.String +@addTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.PartialTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers +@for (var i = 0; i < 100; i++) +{} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartial_Partial.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartial_Partial.cshtml new file mode 100644 index 0000000000..da3f4178ae --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperPartial_Partial.cshtml @@ -0,0 +1,2 @@ +@model System.String +@Model \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperTyped.cshtml b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperTyped.cshtml new file mode 100644 index 0000000000..4eec71bbbf --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance.Views/Views/HelperTyped.cshtml @@ -0,0 +1,7 @@ +@using System; +@using Microsoft.AspNetCore.Html +@model System.String +@{Func SomeHelper = @@{ +@item +};} +@for (var i = 0; i < 100; i++){@SomeHelper(Model + i.ToString())} \ No newline at end of file diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ActionSelectorBenchmark.cs b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ActionSelectorBenchmark.cs index d207316ddc..38d363e9c0 100644 --- a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ActionSelectorBenchmark.cs +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ActionSelectorBenchmark.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/HelperPerformanceBenchmark.cs b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/HelperPerformanceBenchmark.cs new file mode 100644 index 0000000000..572a11a73b --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/HelperPerformanceBenchmark.cs @@ -0,0 +1,49 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.AspNetCore.Mvc.ViewEngines; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Razor.Hosting; +using Microsoft.AspNetCore.Routing; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.ObjectPool; + +namespace Microsoft.AspNetCore.Mvc.Performance +{ + public class HelperPerformanceBenchmark : RuntimePerformanceBenchmarkBase + { + private Random _rand = new Random(); + public HelperPerformanceBenchmark() : base( + "~/Views/HelperTyped.cshtml", + "~/Views/HelperDynamic.cshtml", + "~/Views/HelperPartialSync.cshtml", + "~/Views/HelperPartialAsync.cshtml", + "~/Views/HelperExtensions.cshtml", + "~/Views/HelperPartialTagHelper.cshtml") + { + } + + protected override object Model => _rand.Next().ToString(); + } +} diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/Microsoft.AspNetCore.Mvc.Performance.csproj b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/Microsoft.AspNetCore.Mvc.Performance.csproj index da89cbef0a..c4cbacc80a 100644 --- a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/Microsoft.AspNetCore.Mvc.Performance.csproj +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/Microsoft.AspNetCore.Mvc.Performance.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.0 Exe true true @@ -9,11 +9,15 @@ + + + + diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/MvcEndpointDatasourceBenchmark.cs b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/MvcEndpointDatasourceBenchmark.cs index 028293dd28..efdb91d2f6 100644 --- a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/MvcEndpointDatasourceBenchmark.cs +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/MvcEndpointDatasourceBenchmark.cs @@ -8,7 +8,6 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Patterns; diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/RuntimePerformanceBenchmarkBase.cs b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/RuntimePerformanceBenchmarkBase.cs new file mode 100644 index 0000000000..a763cba861 --- /dev/null +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/RuntimePerformanceBenchmarkBase.cs @@ -0,0 +1,212 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Text.Encodings.Web; +using System.Threading.Tasks; +using BenchmarkDotNet.Attributes; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.AspNetCore.Mvc.Infrastructure; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewEngines; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Razor.Hosting; +using Microsoft.AspNetCore.Routing; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.ObjectPool; +using Microsoft.Extensions.Options; + +namespace Microsoft.AspNetCore.Mvc.Performance +{ + public class RuntimePerformanceBenchmarkBase + { + private class NullLoggerFactory : ILoggerFactory, ILogger + { + void ILoggerFactory.AddProvider(ILoggerProvider provider) {} + ILogger ILoggerFactory.CreateLogger(string categoryName) => this; + void IDisposable.Dispose() {} + IDisposable ILogger.BeginScope(TState state) => null; + bool ILogger.IsEnabled(LogLevel logLevel) => false; + void ILogger.Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) {} + } + + private class BenchmarkViewExecutor : ViewExecutor + { + public BenchmarkViewExecutor(IOptions viewOptions, IHttpResponseStreamWriterFactory writerFactory, ICompositeViewEngine viewEngine, ITempDataDictionaryFactory tempDataFactory, DiagnosticListener diagnosticListener, IModelMetadataProvider modelMetadataProvider) + : base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticListener, modelMetadataProvider) + { + } + + public StringBuilder StringBuilder { get; } = new StringBuilder(); + + public override async Task ExecuteAsync( + ActionContext actionContext, + IView view, + ViewDataDictionary viewData, + ITempDataDictionary tempData, + string contentType, + int? statusCode) + { + using (var stringWriter = new StringWriter(StringBuilder)) + { + var viewContext = new ViewContext( + actionContext, + view, + viewData, + tempData, + stringWriter, + ViewOptions.HtmlHelperOptions); + await ExecuteAsync(viewContext, contentType, statusCode); + await stringWriter.FlushAsync(); + } + + } + } + + + private class BenchmarkHostingEnvironment : IHostingEnvironment + { + public BenchmarkHostingEnvironment() + { + ApplicationName = typeof(ViewAssemblyMarker).Assembly.FullName; + WebRootFileProvider = new NullFileProvider(); + ContentRootFileProvider = new NullFileProvider(); + ContentRootPath = AppContext.BaseDirectory; + WebRootPath = AppContext.BaseDirectory; + } + + public string EnvironmentName { get; set; } + public string ApplicationName { get; set; } + public string WebRootPath { get; set; } + public IFileProvider WebRootFileProvider { get; set; } + public string ContentRootPath { get; set; } + public IFileProvider ContentRootFileProvider { get; set; } + } + + protected RuntimePerformanceBenchmarkBase(params string[] viewPaths) + { + ViewPaths = viewPaths; + } + + public virtual string[] ViewPaths { get; private set; } + + [ParamsSource(nameof(ViewPaths))] + public string ViewPath; + + protected IView View; + + private ServiceProvider _serviceProvider; + private RouteData _routeData; + private ActionDescriptor _actionDescriptor; + private IServiceScope _requestScope; + private ICompositeViewEngine _viewEngine; + private BenchmarkViewExecutor _executor; + private ViewEngineResult _viewEngineResult; + private ActionContext _actionContext; + private ViewDataDictionary _viewDataDictionary; + private ITempDataDictionaryFactory _tempDataDictionaryFactory; + private ITempDataDictionary _tempData; + + // runs once for every Document value + [GlobalSetup] + public void GlobalSetup() + { + var loader = new RazorCompiledItemLoader(); + var viewsDll = Path.ChangeExtension(typeof(ViewAssemblyMarker).Assembly.Location, "Views.dll"); + var viewsAssembly = Assembly.Load(File.ReadAllBytes(viewsDll)); + var services = new ServiceCollection(); + var listener = new DiagnosticListener(GetType().Assembly.FullName); + var partManager = new ApplicationPartManager(); + partManager.ApplicationParts.Add(CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts(viewsAssembly).Single()); + var builder = services + .AddSingleton() + .AddSingleton() + .AddSingleton(listener) + .AddSingleton(listener) + .AddSingleton() + .AddSingleton(partManager) + .AddScoped() + .AddMvc(); + + _serviceProvider = services.BuildServiceProvider(); + _routeData = new RouteData(); + _actionDescriptor = new ActionDescriptor(); + _tempDataDictionaryFactory = _serviceProvider.GetRequiredService(); + _viewEngine = _serviceProvider.GetRequiredService(); + } + + [GlobalCleanup] + public void GlobalCleanup() + { + _serviceProvider.Dispose(); + } + + [IterationSetup] + public virtual void IterationSetup() + { + _requestScope = _serviceProvider.CreateScope(); + + _viewEngineResult = _viewEngine.GetView(null, ViewPath, true); + _viewEngineResult.EnsureSuccessful(null); + + _actionContext = new ActionContext( + new DefaultHttpContext() + { + RequestServices = _requestScope.ServiceProvider + }, + _routeData, + _actionDescriptor); + + _tempData = _tempDataDictionaryFactory.GetTempData(_actionContext.HttpContext); + + _viewDataDictionary = new ViewDataDictionary( + _requestScope.ServiceProvider.GetRequiredService(), + _actionContext.ModelState); + _viewDataDictionary.Model = Model; + + _executor = _requestScope.ServiceProvider.GetRequiredService(); + } + + [IterationCleanup] + public virtual void IterationCleanup() + { + if (_viewEngineResult.View is IDisposable d) + { + d.Dispose(); + } + _requestScope.Dispose(); + } + + protected virtual object Model { get; } = null; + + [Benchmark] + public async Task RenderView() + { + await _executor.ExecuteAsync( + _actionContext, + _viewEngineResult.View, + _viewDataDictionary, + _tempData, + "text/html", + 200); + return _executor.StringBuilder.ToString(); + } + } +} diff --git a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ValidationVisitorBenchmarkBase.cs b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ValidationVisitorBenchmarkBase.cs index cfa12d5f1b..8d66120fd2 100644 --- a/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ValidationVisitorBenchmarkBase.cs +++ b/src/Mvc/benchmarks/Microsoft.AspNetCore.Mvc.Performance/ValidationVisitorBenchmarkBase.cs @@ -6,7 +6,6 @@ using BenchmarkDotNet.Attributes; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.DataAnnotations; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; diff --git a/src/Mvc/build/dependencies.props b/src/Mvc/build/dependencies.props index 063add026b..6f2f0187d0 100644 --- a/src/Mvc/build/dependencies.props +++ b/src/Mvc/build/dependencies.props @@ -16,97 +16,94 @@ 0.43.0 2.1.1.1 2.1.1 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-a-rtm-fix-wildcard-16567 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-preview-181113-11 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 2.0.0 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-a-rtm-allow-required-parameters-17081 - 2.2.0-a-rtm-allow-required-parameters-17081 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 + 3.0.0-preview-181113-11 + 3.0.0-alpha1-10742 5.2.6 - 15.6.82 + 15.8.166 2.8.0 2.8.0 - 2.2.0-rtm-35519 + 3.0.0-alpha1-10742 1.7.0 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.1.0 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview1-26907-05 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-alpha1-10742 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 + 3.0.0-preview-181113-11 2.0.9 2.1.3 - 2.2.0-preview3-27014-02 - 2.2.0-rtm-35519 - 2.2.0-rtm-35519 + 3.0.0-preview1-26907-05 + 3.0.0-alpha1-10742 + 3.0.0-alpha1-10742 15.6.1 4.10.0 2.0.3 1.0.1 11.0.2 - 4.5.0 - 4.5.0 + 4.6.0-preview1-26907-04 + 4.6.0-preview1-26907-04 4.3.2 - 4.5.1 + 4.6.0-preview1-26907-04 0.10.0 2.3.1 2.4.0 diff --git a/src/Mvc/build/repo.props b/src/Mvc/build/repo.props index 3bd17f1b84..4ec5530115 100644 --- a/src/Mvc/build/repo.props +++ b/src/Mvc/build/repo.props @@ -3,6 +3,7 @@ true + true @@ -14,12 +15,11 @@ Internal.AspNetCore.Universe.Lineup - 2.2.0-* https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json - + diff --git a/src/Mvc/buildWithProcDump.cmd b/src/Mvc/buildWithProcDump.cmd new file mode 100644 index 0000000000..c20f050402 --- /dev/null +++ b/src/Mvc/buildWithProcDump.cmd @@ -0,0 +1,2 @@ +@ECHO OFF +PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0runWithProcDump.ps1' %*; exit $LASTEXITCODE" diff --git a/src/Mvc/global.json b/src/Mvc/global.json index b5a5299b58..6df6220662 100644 --- a/src/Mvc/global.json +++ b/src/Mvc/global.json @@ -1,8 +1,8 @@ { "sdk": { - "version": "2.2.100-preview2-009404" + "version": "3.0.100-preview-009750" }, "msbuild-sdks": { - "Internal.AspNetCore.Sdk": "2.2.0-preview2-20181003.2" + "Internal.AspNetCore.Sdk": "3.0.0-build-20181114.5" } } diff --git a/src/Mvc/runWithProcDump.ps1 b/src/Mvc/runWithProcDump.ps1 new file mode 100644 index 0000000000..03d665d662 --- /dev/null +++ b/src/Mvc/runWithProcDump.ps1 @@ -0,0 +1,37 @@ +try +{ + $cwd = $PSScriptRoot; + $job = Start-Job { + $dumpsFolder = "${using:cwd}/artifacts/dumps"; + mkdir $dumpsFolder -Force; + + $procDumpFolder = "${using:cwd}/obj"; + mkdir $procDumpFolder -Force; + + $procDumpFolder = Resolve-Path $procDumpFolder; + Invoke-WebRequest https://download.sysinternals.com/files/Procdump.zip -OutFile "$procDumpFolder/procdump.zip"; + Expand-Archive "$procDumpFolder/procdump.zip" -DestinationPath "$procDumpFolder" -Force; + + $sleepTime = (1 * 20 * 60) + Start-Sleep -Seconds $sleepTime; + Write-Host "Producing dumps in $dumpsFolder"; + Write-Host "Process dumps to capture:" + $processes = Get-Process dotnet*, testhost*; + $processes | Format-Table; + Write-Host "Using ProcDump from $procDumpFolder/procdump.exe"; + + $processes | + Select-Object -ExpandProperty ID | + ForEach-Object { &"$procDumpFolder/procdump.exe" -accepteula -ma $_ $dumpsFolder } + } + Write-Host "Process dump capture job started. Running run.ps1 next"; + ./run.ps1 default-build @args + # Receive-Job $job + Stop-Job $job + Remove-Job $job +} +catch +{ + write-host $_ + exit -1; +} \ No newline at end of file diff --git a/src/Mvc/samples/MvcSandbox/Controllers/LoginController.cs b/src/Mvc/samples/MvcSandbox/Controllers/LoginController.cs new file mode 100644 index 0000000000..5110850fbf --- /dev/null +++ b/src/Mvc/samples/MvcSandbox/Controllers/LoginController.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Mvc; + +namespace MvcSandbox.Controllers +{ + [Route("[controller]/[action]")] + public class LoginController : Controller + { + public IActionResult Index() + { + return View(); + } + } +} diff --git a/src/Mvc/samples/MvcSandbox/HealthChecks/HealthChecksEndpointRouteBuilderExtensions.cs b/src/Mvc/samples/MvcSandbox/HealthChecks/HealthChecksEndpointRouteBuilderExtensions.cs new file mode 100644 index 0000000000..b89acdd2b4 --- /dev/null +++ b/src/Mvc/samples/MvcSandbox/HealthChecks/HealthChecksEndpointRouteBuilderExtensions.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; + +namespace Microsoft.AspNetCore.Builder +{ + public static class HealthChecksEndpointRouteBuilderExtensions + { + private static readonly Random _random = new Random(); + + public static IEndpointConventionBuilder MapHealthChecks(this IEndpointRouteBuilder builder, string pattern) + { + return builder.MapGet( + pattern, + async httpContext => + { + await httpContext.Response.WriteAsync(_random.Next() % 2 == 0 ? "Up!" : "Down!"); + }); + } + } +} diff --git a/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj b/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj index d9e021ff7a..b1668d4793 100644 --- a/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj +++ b/src/Mvc/samples/MvcSandbox/MvcSandbox.csproj @@ -1,8 +1,7 @@ - netcoreapp2.2 - $(TargetFrameworks);net461 + netcoreapp3.0 @@ -11,10 +10,7 @@ - - - diff --git a/src/Mvc/samples/MvcSandbox/Startup.cs b/src/Mvc/samples/MvcSandbox/Startup.cs index d9f96bf08b..dac9f9d057 100644 --- a/src/Mvc/samples/MvcSandbox/Startup.cs +++ b/src/Mvc/samples/MvcSandbox/Startup.cs @@ -1,9 +1,15 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -20,14 +26,43 @@ namespace MvcSandbox // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app) { - app.UseDeveloperExceptionPage(); - app.UseStaticFiles(); - app.UseMvc(routes => + app.UseEndpointRouting(builder => { - routes.MapRoute( + builder.MapGet( + requestDelegate: WriteEndpoints, + pattern: "/endpoints", + displayName: "Home"); + + builder.MapControllerRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); + + builder.MapApplication(); + + builder.MapHealthChecks("/healthz"); }); + + app.UseDeveloperExceptionPage(); + app.UseStaticFiles(); + + app.UseEndpoint(); + } + + private static Task WriteEndpoints(HttpContext httpContext) + { + var dataSource = httpContext.RequestServices.GetRequiredService(); + + var sb = new StringBuilder(); + sb.AppendLine("Endpoints:"); + foreach (var endpoint in dataSource.Endpoints.OfType().OrderBy(e => e.RoutePattern.RawText, StringComparer.OrdinalIgnoreCase)) + { + sb.AppendLine($"- {endpoint.RoutePattern.RawText} '{endpoint.DisplayName}'"); + } + + var response = httpContext.Response; + response.StatusCode = 200; + response.ContentType = "text/plain"; + return response.WriteAsync(sb.ToString()); } public static void Main(string[] args) diff --git a/src/Mvc/src/GetDocumentInsider/Commands/GetDocumentCommandWorker.cs b/src/Mvc/src/GetDocumentInsider/Commands/GetDocumentCommandWorker.cs index af02bd7cc3..f16e5dc8ab 100644 --- a/src/Mvc/src/GetDocumentInsider/Commands/GetDocumentCommandWorker.cs +++ b/src/Mvc/src/GetDocumentInsider/Commands/GetDocumentCommandWorker.cs @@ -109,8 +109,8 @@ namespace Microsoft.Extensions.ApiDescription.Tool.Commands return false; } - var finished = Task.WhenAny(resultTask, Task.Delay(TimeSpan.FromMinutes(1))); - if (!ReferenceEquals(resultTask, finished)) + var finishedIndex = Task.WaitAny(resultTask, Task.Delay(TimeSpan.FromMinutes(1))); + if (finishedIndex != 0) { Reporter.WriteWarning(Resources.FormatMethodTimedOut(methodName, serviceName, 1)); return false; @@ -121,6 +121,8 @@ namespace Microsoft.Extensions.ApiDescription.Tool.Commands using (var outStream = File.Create(context.OutputPath)) { stream.CopyTo(outStream); + + outStream.Flush(); } } diff --git a/src/Mvc/src/GetDocumentInsider/GetDocumentInsider.csproj b/src/Mvc/src/GetDocumentInsider/GetDocumentInsider.csproj index 03d6440c1f..d0ca03bbfd 100644 --- a/src/Mvc/src/GetDocumentInsider/GetDocumentInsider.csproj +++ b/src/Mvc/src/GetDocumentInsider/GetDocumentInsider.csproj @@ -6,6 +6,9 @@ Exe Microsoft.Extensions.ApiDescription.Tool netcoreapp2.0;net461 + false + $(ExperimentalVersionPrefix) + $(ExperimentalVersionSuffix) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Microsoft.AspNetCore.Mvc.Abstractions.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Microsoft.AspNetCore.Mvc.Abstractions.csproj index 34f0f5e6a1..a9b297c080 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Microsoft.AspNetCore.Mvc.Abstractions.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Abstractions/Microsoft.AspNetCore.Mvc.Abstractions.csproj @@ -4,7 +4,7 @@ ASP.NET Core MVC abstractions and interfaces for action invocation and dispatching, authorization, action filters, formatters, model binding, routing, validation, and more. Commonly used types: Microsoft.AspNetCore.Mvc.IActionResult - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs index 6fd8c7e65f..d79f2f148d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/DefaultApiDescriptionProvider.cs @@ -5,10 +5,10 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Template; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/Microsoft.AspNetCore.Mvc.ApiExplorer.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/Microsoft.AspNetCore.Mvc.ApiExplorer.csproj index 308a2f225b..ae3e8a7f34 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/Microsoft.AspNetCore.Mvc.ApiExplorer.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.ApiExplorer/Microsoft.AspNetCore.Mvc.ApiExplorer.csproj @@ -2,7 +2,7 @@ ASP.NET Core MVC API explorer functionality for discovering metadata such as the list of controllers and actions, and their URLs and allowed HTTP methods. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionConstraintCache.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/ActionConstraintCache.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionConstraintCache.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/ActionConstraintCache.cs index 384d48bffa..238fbfba82 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionConstraintCache.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/ActionConstraintCache.cs @@ -7,12 +7,11 @@ using System.Diagnostics; using System.Linq; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; -using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.Infrastructure; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ActionConstraints { - public class ActionConstraintCache + internal class ActionConstraintCache { private readonly IActionDescriptorCollectionProvider _collectionProvider; private readonly IActionConstraintProvider[] _actionConstraintProviders; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultActionConstraintProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/DefaultActionConstraintProvider.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultActionConstraintProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/DefaultActionConstraintProvider.cs index 571f3ebebf..fe44d25be7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultActionConstraintProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/DefaultActionConstraintProvider.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.ActionConstraints; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ActionConstraints { /// /// A default implementation of . @@ -14,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// implements or /// / /// - public class DefaultActionConstraintProvider : IActionConstraintProvider + internal class DefaultActionConstraintProvider : IActionConstraintProvider { /// public int Order => -1000; @@ -61,4 +60,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpMethodActionConstraint.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/HttpMethodActionConstraint.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpMethodActionConstraint.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/HttpMethodActionConstraint.cs index e310493486..4385e734e5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpMethodActionConstraint.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/HttpMethodActionConstraint.cs @@ -4,12 +4,10 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using Microsoft.AspNetCore.Mvc.ActionConstraints; -using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ActionConstraints { - public class HttpMethodActionConstraint : IActionConstraint + internal class HttpMethodActionConstraint : IActionConstraint { public static readonly int HttpMethodConstraintOrder = 100; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IConsumesActionConstraint.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/IConsumesActionConstraint.cs similarity index 69% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IConsumesActionConstraint.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/IConsumesActionConstraint.cs index b004cbdcf3..9e368fe825 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IConsumesActionConstraint.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ActionConstraints/IConsumesActionConstraint.cs @@ -1,15 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.ActionConstraints; - -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ActionConstraints { /// /// An constraint that identifies a type which can be used to select an action /// based on incoming request. /// - public interface IConsumesActionConstraint : IActionConstraint + internal interface IConsumesActionConstraint : IActionConstraint { } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApiDescriptionActionData.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApiExplorer/ApiDescriptionActionData.cs similarity index 86% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApiDescriptionActionData.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApiExplorer/ApiDescriptionActionData.cs index 1a24b3d8bd..bba3427bd7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApiDescriptionActionData.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApiExplorer/ApiDescriptionActionData.cs @@ -1,13 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc { /// /// Represents data used to build an ApiDescription, stored as part of the /// . /// - public class ApiDescriptionActionData + internal class ApiDescriptionActionData { /// /// The ApiDescription.GroupName of ApiDescription objects for the associated @@ -15,4 +15,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// public string GroupName { get; set; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ActionAttributeRouteModel.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ActionAttributeRouteModel.cs new file mode 100644 index 0000000000..b7a60f3362 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ActionAttributeRouteModel.cs @@ -0,0 +1,189 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Mvc.ActionConstraints; +using Microsoft.AspNetCore.Mvc.Routing; + +namespace Microsoft.AspNetCore.Mvc.ApplicationModels +{ + internal static class ActionAttributeRouteModel + { + public static IEnumerable FlattenSelectors(ActionModel actionModel) + { + // Loop through all attribute routes defined on the controller. + // These perform a cross-product with all of the action-level attribute routes. + var controllerSelectors = actionModel.Controller.Selectors + .Where(sm => sm.AttributeRouteModel != null) + .ToList(); + + // We also include metadata and action constraints from the controller + // even when there are no routes, or when an action overrides the route template. + SelectorModel additionalSelector = null; + if (actionModel.Controller.Selectors.Count > 0) + { + // This logic seems arbitrary but there's a good reason for it. + // + // When we build the controller level selectors, any metadata or action constraints + // that aren't IRouteTemplateProvider will be included in all selectors. So we + // pick any selector and then grab all of the stuff that isn't IRouteTemplateProvider + // then we've found all of the items that aren't routes. + // + // This is fragile wrt application model customizing the data - but no one has + // run into an issue with this and its pretty esoteric. + additionalSelector = new SelectorModel(actionModel.Controller.Selectors.First()); + additionalSelector.AttributeRouteModel = null; + + for (var i = additionalSelector.ActionConstraints.Count - 1; i >= 0; i--) + { + if (additionalSelector.ActionConstraints[i] is IRouteTemplateProvider) + { + additionalSelector.ActionConstraints.RemoveAt(i); + } + } + + for (var i = additionalSelector.EndpointMetadata.Count - 1; i >= 0; i--) + { + if (additionalSelector.EndpointMetadata[i] is IRouteTemplateProvider) + { + additionalSelector.EndpointMetadata.RemoveAt(i); + } + } + } + + var actionConstraints = new List(); + + foreach (var actionSelector in actionModel.Selectors) + { + var actionRouteModel = actionSelector.AttributeRouteModel; + + // We check the action to see if the template allows combination behavior + // (It doesn't start with / or ~/) so that in the case where we have multiple + // [Route] attributes on the controller we don't end up creating multiple + if (actionRouteModel != null && actionRouteModel.IsAbsoluteTemplate) + { + // We're overriding the routes from the controller, but any *unbound* constraints + // still apply. + var selector = new SelectorModel(actionSelector); + + selector.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel( + left: null, + right: actionRouteModel); + + AddActionConstraints(selector, additionalSelector?.ActionConstraints); + AddEndpointMetadata(selector, additionalSelector?.EndpointMetadata); + + yield return selector; + } + else if (controllerSelectors.Count > 0) + { + for (var i = 0; i < controllerSelectors.Count; i++) + { + var controllerSelector = controllerSelectors[i]; + + // We're using the attribute routes from the controller + var selector = new SelectorModel(actionSelector); + + selector.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel( + controllerSelector.AttributeRouteModel, + actionRouteModel); + + AddActionConstraints(selector, controllerSelector.ActionConstraints); + AddEndpointMetadata(selector, controllerSelector.EndpointMetadata); + + // No need to include the additional selector here because it would duplicate + // data in controllerSelector. + + yield return selector; + } + } + else + { + // There are no routes on the controller, but any *unbound* constraints + // still apply. + var selector = new SelectorModel(actionSelector); + + selector.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel( + left: null, + right: actionRouteModel); + + AddActionConstraints(selector, additionalSelector?.ActionConstraints); + AddEndpointMetadata(selector, additionalSelector?.EndpointMetadata); + + yield return selector; + } + } + } + + private static void AddActionConstraints(SelectorModel selector, IList actionConstraints) + { + if (actionConstraints != null) + { + for (var i = 0; i < actionConstraints.Count;i++) + { + selector.ActionConstraints.Add(actionConstraints[i]); + } + } + } + + private static void AddEndpointMetadata(SelectorModel selector, IList metadata) + { + if (metadata != null) + { + for (var i = 0; i < metadata.Count; i++) + { + selector.EndpointMetadata.Add(metadata[i]); + } + } + } + + public static IEnumerable<(AttributeRouteModel route, SelectorModel actionSelector, SelectorModel controllerSelector)> GetAttributeRoutes(ActionModel actionModel) + { + var controllerAttributeRoutes = actionModel.Controller.Selectors + .Where(sm => sm.AttributeRouteModel != null) + .Select(sm => sm.AttributeRouteModel) + .ToList(); + + foreach (var actionSelectorModel in actionModel.Selectors) + { + var actionRouteModel = actionSelectorModel.AttributeRouteModel; + + // We check the action to see if the template allows combination behavior + // (It doesn't start with / or ~/) so that in the case where we have multiple + // [Route] attributes on the controller we don't end up creating multiple + if (actionRouteModel != null && actionRouteModel.IsAbsoluteTemplate) + { + var route = AttributeRouteModel.CombineAttributeRouteModel( + left: null, + right: actionRouteModel); + + yield return (route, actionSelectorModel, null); + } + else if (controllerAttributeRoutes.Count > 0) + { + for (var i = 0; i < actionModel.Controller.Selectors.Count; i++) + { + // We're using the attribute routes from the controller + var controllerSelector = actionModel.Controller.Selectors[i]; + + var route = AttributeRouteModel.CombineAttributeRouteModel( + controllerSelector.AttributeRouteModel, + actionRouteModel); + + yield return (route, actionSelectorModel, controllerSelector); + } + } + + else + { + var route = AttributeRouteModel.CombineAttributeRouteModel( + left: null, + right: actionRouteModel); + + yield return (route, actionSelectorModel, null); + } + } + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ActionModel.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ActionModel.cs index 59cc05b4e4..9571152114 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ActionModel.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ActionModel.cs @@ -50,6 +50,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels ActionMethod = other.ActionMethod; ActionName = other.ActionName; + RouteParameterTransformer = other.RouteParameterTransformer; // Not making a deep copy of the controller, this action still belongs to the same controller. Controller = other.Controller; @@ -93,6 +94,18 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels public IList Parameters { get; } + /// + /// Gets or sets an that will be used to transform + /// built-in route parameters such as action, controller, and area as well as + /// additional parameters specified by into static segments in the route template. + /// + /// + /// + /// This feature only applies when using endpoint routing. + /// + /// + public IOutboundParameterTransformer RouteParameterTransformer { get; set; } + /// /// Gets a collection of route values that must be present in the /// for the corresponding action to be selected. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApiBehaviorApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApiBehaviorApplicationModelProvider.cs index 35a415297b..d987344e85 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApiBehaviorApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApiBehaviorApplicationModelProvider.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApplicationModelConventions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModelConventions.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApplicationModelConventions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModelConventions.cs index 108890f5ce..6bd39d3391 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApplicationModelConventions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModelConventions.cs @@ -4,14 +4,13 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Mvc.ApplicationModels; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { /// /// Applies conventions to a . /// - public static class ApplicationModelConventions + internal static class ApplicationModelConventions { /// /// Applies conventions to a . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModelFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModelFactory.cs new file mode 100644 index 0000000000..fae18d4481 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ApplicationModelFactory.cs @@ -0,0 +1,361 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using Microsoft.AspNetCore.Mvc.ActionConstraints; +using Microsoft.AspNetCore.Mvc.Core; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Options; + +namespace Microsoft.AspNetCore.Mvc.ApplicationModels +{ + /// + /// A facade service for creating application models. + /// + internal class ApplicationModelFactory + { + private readonly IApplicationModelProvider[] _applicationModelProviders; + private readonly IList _conventions; + + public ApplicationModelFactory( + IEnumerable applicationModelProviders, + IOptions options) + { + if (applicationModelProviders == null) + { + throw new ArgumentNullException(nameof(applicationModelProviders)); + } + + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + + _applicationModelProviders = applicationModelProviders.OrderBy(p => p.Order).ToArray(); + _conventions = options.Value.Conventions; + } + + public ApplicationModel CreateApplicationModel(IEnumerable controllerTypes) + { + if (controllerTypes == null) + { + throw new ArgumentNullException(nameof(controllerTypes)); + } + + var context = new ApplicationModelProviderContext(controllerTypes); + + for (var i = 0; i < _applicationModelProviders.Length; i++) + { + _applicationModelProviders[i].OnProvidersExecuting(context); + } + + for (var i = _applicationModelProviders.Length - 1; i >= 0; i--) + { + _applicationModelProviders[i].OnProvidersExecuted(context); + } + + ApplicationModelConventions.ApplyConventions(context.Result, _conventions); + + return context.Result; + } + + public static List Flatten( + ApplicationModel application, + Func flattener) + { + var results = new List(); + var errors = new Dictionary>(); + + var actionsByMethod = new Dictionary>(); + var actionsByRouteName = new Dictionary>(StringComparer.OrdinalIgnoreCase); + + var routeTemplateErrors = new List(); + + foreach (var controller in application.Controllers) + { + foreach (var action in controller.Actions) + { + foreach (var selector in ActionAttributeRouteModel.FlattenSelectors(action)) + { + // PostProcess attribute routes so we can observe any errors. + ReplaceAttributeRouteTokens(controller, action, selector, routeTemplateErrors); + + // Add to the data structures we use to find errors. + AddActionToMethodInfoMap(actionsByMethod, action, selector); + AddActionToRouteNameMap(actionsByRouteName, action, selector); + + var result = flattener(application, controller, action, selector); + Debug.Assert(result != null); + + results.Add(result); + } + } + } + + var attributeRoutingConfigurationErrors = new Dictionary(); + foreach (var (method, actions) in actionsByMethod) + { + ValidateActionGroupConfiguration( + method, + actions, + attributeRoutingConfigurationErrors); + } + + if (attributeRoutingConfigurationErrors.Any()) + { + var message = CreateAttributeRoutingAggregateErrorMessage(attributeRoutingConfigurationErrors.Values); + + throw new InvalidOperationException(message); + } + + var namedRoutedErrors = ValidateNamedAttributeRoutedActions(actionsByRouteName); + if (namedRoutedErrors.Any()) + { + var message = CreateAttributeRoutingAggregateErrorMessage(namedRoutedErrors); + throw new InvalidOperationException(message); + } + + if (routeTemplateErrors.Any()) + { + var message = CreateAttributeRoutingAggregateErrorMessage(routeTemplateErrors); + throw new InvalidOperationException(message); + } + + + return results; + } + + private static void ReplaceAttributeRouteTokens( + ControllerModel controller, + ActionModel action, + SelectorModel selector, + List errors) + { + if (selector.AttributeRouteModel == null) + { + return; + } + + try + { + var routeValues = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + { "action", action.ActionName }, + { "controller", controller.ControllerName }, + }; + + foreach (var kvp in action.RouteValues) + { + routeValues.TryAdd(kvp.Key, kvp.Value); + } + + foreach (var kvp in controller.RouteValues) + { + routeValues.TryAdd(kvp.Key, kvp.Value); + } + + selector.AttributeRouteModel.Template = AttributeRouteModel.ReplaceTokens( + selector.AttributeRouteModel.Template, + routeValues, + action.RouteParameterTransformer); + + if (selector.AttributeRouteModel.Name != null) + { + selector.AttributeRouteModel.Name = AttributeRouteModel.ReplaceTokens( + selector.AttributeRouteModel.Name, + routeValues, + action.RouteParameterTransformer); + } + } + catch (InvalidOperationException ex) + { + // Routing will throw an InvalidOperationException here if we can't parse/replace tokens + // in the template. + var message = Resources.FormatAttributeRoute_IndividualErrorMessage( + action.DisplayName, + Environment.NewLine, + ex.Message); + + errors.Add(message); + } + } + + private static void AddActionToMethodInfoMap( + Dictionary> actionsByMethod, + ActionModel action, + SelectorModel selector) + { + if (!actionsByMethod.TryGetValue(action.ActionMethod, out var actions)) + { + actions = new List<(ActionModel, SelectorModel)>(); + actionsByMethod.Add(action.ActionMethod, actions); + } + + actions.Add((action, selector)); + } + + private static void AddActionToRouteNameMap( + Dictionary> actionsByRouteName, + ActionModel action, + SelectorModel selector) + { + var routeName = selector.AttributeRouteModel?.Name; + if (selector.AttributeRouteModel?.Name == null) + { + return; + } + + if (!actionsByRouteName.TryGetValue(routeName, out var actions)) + { + actions = new List<(ActionModel, SelectorModel)>(); + actionsByRouteName.Add(routeName, actions); + } + + actions.Add((action, selector)); + } + + private static List AddErrorNumbers(IEnumerable namedRoutedErrors) + { + return namedRoutedErrors + .Select((error, i) => + Resources.FormatAttributeRoute_AggregateErrorMessage_ErrorNumber( + i + 1, + Environment.NewLine, + error)) + .ToList(); + } + + private static List ValidateNamedAttributeRoutedActions( + Dictionary> actionsByRouteName) + { + var namedRouteErrors = new List(); + + foreach (var (routeName, actions) in actionsByRouteName) + { + // We are looking for attribute routed actions that have the same name but + // different route templates. We pick the first template of the group and + // we compare it against the rest of the templates that have that same name + // associated. + // The moment we find one that is different we report the whole group to the + // user in the error message so that he can see the different actions and the + // different templates for a given named attribute route. + var template = actions[0].selector.AttributeRouteModel.Template; + + for (var i = 1; i < actions.Count; i++) + { + var other = actions[i].selector.AttributeRouteModel.Template; + + if (!template.Equals(other, StringComparison.OrdinalIgnoreCase)) + { + var descriptions = actions.Select(a => + { + return Resources.FormatAttributeRoute_DuplicateNames_Item(a.action.DisplayName, a.selector.AttributeRouteModel.Template); + }); + + var message = Resources.FormatAttributeRoute_DuplicateNames(routeName, Environment.NewLine, string.Join(Environment.NewLine, descriptions)); + namedRouteErrors.Add(message); + break; + } + } + } + + return namedRouteErrors; + } + + private static void ValidateActionGroupConfiguration( + MethodInfo method, + List<(ActionModel action, SelectorModel selector)> actions, + IDictionary routingConfigurationErrors) + { + var hasAttributeRoutedActions = false; + var hasConventionallyRoutedActions = false; + + for (var i = 0; i < actions.Count; i++) + { + if (actions[i].selector.AttributeRouteModel == null) + { + hasConventionallyRoutedActions = true; + } + else + { + hasAttributeRoutedActions = true; + } + } + + // Validate that no method result in attribute and non attribute actions at the same time. + // By design, mixing attribute and conventionally actions in the same method is not allowed. + // + // Assuming the controller doesn't specify a route template, this example would not be allowed: + // + // [HttpGet] + // [HttpPost("Foo")] + // public void Foo() { } + if (hasAttributeRoutedActions && hasConventionallyRoutedActions) + { + var message = CreateMixedRoutedActionDescriptorsErrorMessage(method, actions); + routingConfigurationErrors.Add(method, message); + } + } + + private static string CreateMixedRoutedActionDescriptorsErrorMessage( + MethodInfo method, + List<(ActionModel action, SelectorModel selector)> actions) + { + // Text to show as the attribute route template for conventionally routed actions. + var nullTemplate = Resources.AttributeRoute_NullTemplateRepresentation; + + var actionDescriptions = new List(); + for (var i = 0; i < actions.Count; i++) + { + var (action, selector) = actions[i]; + var routeTemplate = selector.AttributeRouteModel?.Template ?? nullTemplate; + + var verbs = selector.ActionConstraints?.OfType().FirstOrDefault()?.HttpMethods; + + var formattedVerbs = string.Empty; + if (verbs != null) + { + formattedVerbs = string.Join(", ", verbs.OrderBy(v => v, StringComparer.OrdinalIgnoreCase)); + } + + var description = Resources.FormatAttributeRoute_MixedAttributeAndConventionallyRoutedActions_ForMethod_Item( + action.DisplayName, + routeTemplate, + formattedVerbs); + + actionDescriptions.Add(description); + } + + // Sample error message: + // + // A method 'MyApplication.CustomerController.Index' must not define attributed actions and + // non attributed actions at the same time: + // Action: 'MyApplication.CustomerController.Index' - Route Template: 'Products' - HTTP Verbs: 'PUT' + // Action: 'MyApplication.CustomerController.Index' - Route Template: '(none)' - HTTP Verbs: 'POST' + // + // Use 'AcceptVerbsAttribute' to create a single route that allows multiple HTTP verbs and defines a route, + // or set a route template in all attributes that constrain HTTP verbs. + + var formattedMethodInfo = $"{TypeNameHelper.GetTypeDisplayName(method.ReflectedType)}.{method.Name} ({method.ReflectedType.Assembly.GetName().Name})"; + return Resources.FormatAttributeRoute_MixedAttributeAndConventionallyRoutedActions_ForMethod( + formattedMethodInfo, + Environment.NewLine, + string.Join(Environment.NewLine, actionDescriptions)); + } + + private static string CreateAttributeRoutingAggregateErrorMessage(IEnumerable individualErrors) + { + var errorMessages = AddErrorNumbers(individualErrors); + + var message = Resources.FormatAttributeRoute_AggregateErrorMessage( + Environment.NewLine, + string.Join(Environment.NewLine + Environment.NewLine, errorMessages)); + return message; + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AuthorizationApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/AuthorizationApplicationModelProvider.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AuthorizationApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/AuthorizationApplicationModelProvider.cs index 3166c9deb0..34c7a31dd4 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AuthorizationApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/AuthorizationApplicationModelProvider.cs @@ -5,12 +5,11 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Authorization; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { - public class AuthorizationApplicationModelProvider : IApplicationModelProvider + internal class AuthorizationApplicationModelProvider : IApplicationModelProvider { private readonly IAuthorizationPolicyProvider _policyProvider; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ConsumesConstraintForFormFileParameterConvention.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ConsumesConstraintForFormFileParameterConvention.cs index 714856e11d..6ad528161b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ConsumesConstraintForFormFileParameterConvention.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ConsumesConstraintForFormFileParameterConvention.cs @@ -3,7 +3,7 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Microsoft.AspNetCore.Mvc.ApplicationModels diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ControllerActionDescriptorBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ControllerActionDescriptorBuilder.cs new file mode 100644 index 0000000000..c53234af3e --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ControllerActionDescriptorBuilder.cs @@ -0,0 +1,259 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.ActionConstraints; +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.Routing; +using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; + +namespace Microsoft.AspNetCore.Mvc.ApplicationModels +{ + /// + /// Creates instances of from application model + /// types. + /// + internal static class ControllerActionDescriptorBuilder + { + public static IList Build(ApplicationModel application) + { + return ApplicationModelFactory.Flatten(application, CreateActionDescriptor); + } + + private static ControllerActionDescriptor CreateActionDescriptor( + ApplicationModel application, + ControllerModel controller, + ActionModel action, + SelectorModel selector) + { + var actionDescriptor = new ControllerActionDescriptor + { + ActionName = action.ActionName, + MethodInfo = action.ActionMethod, + }; + + actionDescriptor.ControllerName = controller.ControllerName; + actionDescriptor.ControllerTypeInfo = controller.ControllerType; + AddControllerPropertyDescriptors(actionDescriptor, controller); + + AddActionConstraints(actionDescriptor, selector); + AddEndpointMetadata(actionDescriptor, selector); + AddAttributeRoute(actionDescriptor, selector); + AddParameterDescriptors(actionDescriptor, action); + AddActionFilters(actionDescriptor, action.Filters, controller.Filters, application.Filters); + AddApiExplorerInfo(actionDescriptor, application, controller, action); + AddRouteValues(actionDescriptor, controller, action); + AddProperties(actionDescriptor, action, controller, application); + + return actionDescriptor; + } + + private static void AddControllerPropertyDescriptors(ActionDescriptor actionDescriptor, ControllerModel controller) + { + actionDescriptor.BoundProperties = controller.ControllerProperties + .Where(p => p.BindingInfo != null) + .Select(CreateParameterDescriptor) + .ToList(); + } + + private static void AddParameterDescriptors(ActionDescriptor actionDescriptor, ActionModel action) + { + var parameterDescriptors = new List(); + foreach (var parameter in action.Parameters) + { + var parameterDescriptor = CreateParameterDescriptor(parameter); + parameterDescriptors.Add(parameterDescriptor); + } + + actionDescriptor.Parameters = parameterDescriptors; + } + + private static ParameterDescriptor CreateParameterDescriptor(ParameterModel parameterModel) + { + var parameterDescriptor = new ControllerParameterDescriptor() + { + Name = parameterModel.ParameterName, + ParameterType = parameterModel.ParameterInfo.ParameterType, + BindingInfo = parameterModel.BindingInfo, + ParameterInfo = parameterModel.ParameterInfo, + }; + + return parameterDescriptor; + } + + private static ParameterDescriptor CreateParameterDescriptor(PropertyModel propertyModel) + { + var parameterDescriptor = new ControllerBoundPropertyDescriptor() + { + BindingInfo = propertyModel.BindingInfo, + Name = propertyModel.PropertyName, + ParameterType = propertyModel.PropertyInfo.PropertyType, + PropertyInfo = propertyModel.PropertyInfo, + }; + + return parameterDescriptor; + } + + private static void AddApiExplorerInfo( + ControllerActionDescriptor actionDescriptor, + ApplicationModel application, + ControllerModel controller, + ActionModel action) + { + var isVisible = + action.ApiExplorer?.IsVisible ?? + controller.ApiExplorer?.IsVisible ?? + application.ApiExplorer?.IsVisible ?? + false; + + var isVisibleSetOnActionOrController = + action.ApiExplorer?.IsVisible ?? + controller.ApiExplorer?.IsVisible ?? + false; + + // ApiExplorer isn't supported on conventional-routed actions, but we still allow you to configure + // it at the application level when you have a mix of controller types. We'll just skip over enabling + // ApiExplorer for conventional-routed controllers when this happens. + var isVisibleSetOnApplication = application.ApiExplorer?.IsVisible ?? false; + + if (isVisibleSetOnActionOrController && !IsAttributeRouted(actionDescriptor)) + { + // ApiExplorer is only supported on attribute routed actions. + throw new InvalidOperationException(Resources.FormatApiExplorer_UnsupportedAction( + actionDescriptor.DisplayName)); + } + else if (isVisibleSetOnApplication && !IsAttributeRouted(actionDescriptor)) + { + // This is the case where we're going to be lenient, just ignore it. + } + else if (isVisible) + { + Debug.Assert(IsAttributeRouted(actionDescriptor)); + + var apiExplorerActionData = new ApiDescriptionActionData() + { + GroupName = action.ApiExplorer?.GroupName ?? controller.ApiExplorer?.GroupName, + }; + + actionDescriptor.SetProperty(apiExplorerActionData); + } + } + + private static void AddProperties( + ControllerActionDescriptor actionDescriptor, + ActionModel action, + ControllerModel controller, + ApplicationModel application) + { + foreach (var item in application.Properties) + { + actionDescriptor.Properties[item.Key] = item.Value; + } + + foreach (var item in controller.Properties) + { + actionDescriptor.Properties[item.Key] = item.Value; + } + + foreach (var item in action.Properties) + { + actionDescriptor.Properties[item.Key] = item.Value; + } + } + + private static void AddActionFilters( + ControllerActionDescriptor actionDescriptor, + IEnumerable actionFilters, + IEnumerable controllerFilters, + IEnumerable globalFilters) + { + actionDescriptor.FilterDescriptors = + actionFilters.Select(f => new FilterDescriptor(f, FilterScope.Action)) + .Concat(controllerFilters.Select(f => new FilterDescriptor(f, FilterScope.Controller))) + .Concat(globalFilters.Select(f => new FilterDescriptor(f, FilterScope.Global))) + .OrderBy(d => d, FilterDescriptorOrderComparer.Comparer) + .ToList(); + } + + private static void AddActionConstraints(ControllerActionDescriptor actionDescriptor, SelectorModel selectorModel) + { + if (selectorModel.ActionConstraints?.Count > 0) + { + actionDescriptor.ActionConstraints = new List(selectorModel.ActionConstraints); + } + } + + private static void AddEndpointMetadata(ControllerActionDescriptor actionDescriptor, SelectorModel selectorModel) + { + if (selectorModel.EndpointMetadata?.Count > 0) + { + actionDescriptor.EndpointMetadata = new List(selectorModel.EndpointMetadata); + } + } + + private static void AddAttributeRoute(ControllerActionDescriptor actionDescriptor, SelectorModel selectorModel) + { + if (selectorModel.AttributeRouteModel != null) + { + actionDescriptor.AttributeRouteInfo = new AttributeRouteInfo + { + Template = selectorModel.AttributeRouteModel.Template, + Order = selectorModel.AttributeRouteModel.Order ?? 0, + Name = selectorModel.AttributeRouteModel.Name, + SuppressLinkGeneration = selectorModel.AttributeRouteModel.SuppressLinkGeneration, + SuppressPathMatching = selectorModel.AttributeRouteModel.SuppressPathMatching, + }; + } + } + + public static void AddRouteValues( + ControllerActionDescriptor actionDescriptor, + ControllerModel controller, + ActionModel action) + { + // Apply all the constraints defined on the action, then controller (for example, [Area]) + // to the actions. Also keep track of all the constraints that require preventing actions + // without the constraint to match. For example, actions without an [Area] attribute on their + // controller should not match when a value has been given for area when matching a url or + // generating a link. + foreach (var kvp in action.RouteValues) + { + // Skip duplicates + if (!actionDescriptor.RouteValues.ContainsKey(kvp.Key)) + { + actionDescriptor.RouteValues.Add(kvp.Key, kvp.Value); + } + } + + foreach (var kvp in controller.RouteValues) + { + // Skip duplicates - this also means that a value on the action will take precedence + if (!actionDescriptor.RouteValues.ContainsKey(kvp.Key)) + { + actionDescriptor.RouteValues.Add(kvp.Key, kvp.Value); + } + } + + // Lastly add the 'default' values + if (!actionDescriptor.RouteValues.ContainsKey("action")) + { + actionDescriptor.RouteValues.Add("action", action.ActionName ?? string.Empty); + } + + if (!actionDescriptor.RouteValues.ContainsKey("controller")) + { + actionDescriptor.RouteValues.Add("controller", controller.ControllerName); + } + } + + private static bool IsAttributeRouted(ActionDescriptor actionDescriptor) + { + return actionDescriptor.AttributeRouteInfo != null; + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ControllerActionDescriptorProvider.cs similarity index 64% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ControllerActionDescriptorProvider.cs index c5fc31e178..e82b715697 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/ControllerActionDescriptorProvider.cs @@ -3,45 +3,34 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc.Abstractions; -using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; -using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { - public class ControllerActionDescriptorProvider : IActionDescriptorProvider + internal class ControllerActionDescriptorProvider : IActionDescriptorProvider { private readonly ApplicationPartManager _partManager; - private readonly IApplicationModelProvider[] _applicationModelProviders; - private readonly IEnumerable _conventions; + private readonly ApplicationModelFactory _applicationModelFactory; public ControllerActionDescriptorProvider( ApplicationPartManager partManager, - IEnumerable applicationModelProviders, - IOptions optionsAccessor) + ApplicationModelFactory applicationModelFactory) { if (partManager == null) { throw new ArgumentNullException(nameof(partManager)); } - if (applicationModelProviders == null) + if (applicationModelFactory == null) { - throw new ArgumentNullException(nameof(applicationModelProviders)); - } - - if (optionsAccessor == null) - { - throw new ArgumentNullException(nameof(optionsAccessor)); + throw new ArgumentNullException(nameof(applicationModelFactory)); } _partManager = partManager; - _applicationModelProviders = applicationModelProviders.OrderBy(p => p.Order).ToArray(); - _conventions = optionsAccessor.Value.Conventions; + _applicationModelFactory = applicationModelFactory; } public int Order => -1000; @@ -63,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// public void OnProvidersExecuted(ActionDescriptorProviderContext context) { - // After all of the providers have run, we need to provide a 'null' for each all of route values that + // After all of the providers have run, we need to provide a 'null' for each all of route values that // participate in action selection. // // This is important for scenarios like Razor Pages, that use the 'page' route value. An action that @@ -95,29 +84,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } - protected internal IEnumerable GetDescriptors() - { - var applicationModel = BuildModel(); - ApplicationModelConventions.ApplyConventions(applicationModel, _conventions); - return ControllerActionDescriptorBuilder.Build(applicationModel); - } - - protected internal ApplicationModel BuildModel() + internal IEnumerable GetDescriptors() { var controllerTypes = GetControllerTypes(); - var context = new ApplicationModelProviderContext(controllerTypes); - - for (var i = 0; i < _applicationModelProviders.Length; i++) - { - _applicationModelProviders[i].OnProvidersExecuting(context); - } - - for (var i = _applicationModelProviders.Length - 1; i >= 0; i--) - { - _applicationModelProviders[i].OnProvidersExecuted(context); - } - - return context.Result; + var application = _applicationModelFactory.CreateApplicationModel(controllerTypes); + return ControllerActionDescriptorBuilder.Build(application); } private IEnumerable GetControllerTypes() diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/DefaultApplicationModelProvider.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/DefaultApplicationModelProvider.cs index c79b2b209d..b1b23d9a93 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/DefaultApplicationModelProvider.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Routing; @@ -15,9 +14,9 @@ using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { - public class DefaultApplicationModelProvider : IApplicationModelProvider + internal class DefaultApplicationModelProvider : IApplicationModelProvider { private readonly MvcOptions _mvcOptions; private readonly IModelMetadataProvider _modelMetadataProvider; @@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal public int Order => -1000; /// - public virtual void OnProvidersExecuting(ApplicationModelProviderContext context) + public void OnProvidersExecuting(ApplicationModelProviderContext context) { if (context == null) { @@ -98,7 +97,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } /// - public virtual void OnProvidersExecuted(ApplicationModelProviderContext context) + public void OnProvidersExecuted(ApplicationModelProviderContext context) { // Intentionally empty. } @@ -108,7 +107,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// The . /// A for the given . - protected virtual ControllerModel CreateControllerModel(TypeInfo typeInfo) + internal ControllerModel CreateControllerModel(TypeInfo typeInfo) { if (typeInfo == null) { @@ -215,7 +214,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// The . /// A for the given . - protected virtual PropertyModel CreatePropertyModel(PropertyInfo propertyInfo) + internal PropertyModel CreatePropertyModel(PropertyInfo propertyInfo) { if (propertyInfo == null) { @@ -263,7 +262,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// An instance for the given action or /// null if the does not represent an action. /// - protected virtual ActionModel CreateActionModel( + internal ActionModel CreateActionModel( TypeInfo typeInfo, MethodInfo methodInfo) { @@ -381,7 +380,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// Override this method to provide custom logic to determine which methods are considered actions. /// - protected virtual bool IsAction(TypeInfo typeInfo, MethodInfo methodInfo) + internal bool IsAction(TypeInfo typeInfo, MethodInfo methodInfo) { if (typeInfo == null) { @@ -445,7 +444,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// The . /// A for the given . - protected virtual ParameterModel CreateParameterModel(ParameterInfo parameterInfo) + internal ParameterModel CreateParameterModel(ParameterInfo parameterInfo) { if (parameterInfo == null) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/InferParameterBindingInfoConvention.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/InferParameterBindingInfoConvention.cs index 9a3839308a..0148be60b9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/InferParameterBindingInfoConvention.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/InferParameterBindingInfoConvention.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Routing.Template; using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; @@ -99,14 +98,14 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels private bool ParameterExistsInAnyRoute(ActionModel action, string parameterName) { - foreach (var (route, _, _) in ActionAttributeRouteModel.GetAttributeRoutes(action)) + foreach (var selector in ActionAttributeRouteModel.FlattenSelectors(action)) { - if (route == null) + if (selector.AttributeRouteModel == null) { continue; } - var parsedTemplate = TemplateParser.Parse(route.Template); + var parsedTemplate = TemplateParser.Parse(selector.AttributeRouteModel.Template); if (parsedTemplate.GetParameter(parameterName) != null) { return true; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/RouteTokenTransformerConvention.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/RouteTokenTransformerConvention.cs index 004e4a22c3..44492420c1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/RouteTokenTransformerConvention.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/RouteTokenTransformerConvention.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels { if (ShouldApply(action)) { - action.Properties[typeof(IOutboundParameterTransformer)] = _parameterTransformer; + action.RouteParameterTransformer = _parameterTransformer; } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationParts/ApplicationAssembliesProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationParts/ApplicationAssembliesProvider.cs index 08149805ff..b1d414a8ca 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationParts/ApplicationAssembliesProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ApplicationParts/ApplicationAssembliesProvider.cs @@ -14,10 +14,10 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts { internal static HashSet ReferenceAssemblies { get; } = new HashSet(StringComparer.OrdinalIgnoreCase) { - // The deps file for the Microsoft.AspNetCore.All shared runtime is authored in a way where it does not say + // The deps file for the Microsoft.AspNetCore.App shared runtime is authored in a way where it does not say // it depends on Microsoft.AspNetCore.Mvc even though it does. Explicitly list it so that referencing this runtime causes // assembly discovery to work correctly. - "Microsoft.AspNetCore.All", + "Microsoft.AspNetCore.App", "Microsoft.AspNetCore.Mvc", "Microsoft.AspNetCore.Mvc.Abstractions", "Microsoft.AspNetCore.Mvc.ApiExplorer", @@ -28,7 +28,6 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts "Microsoft.AspNetCore.Mvc.Formatters.Xml", "Microsoft.AspNetCore.Mvc.Localization", "Microsoft.AspNetCore.Mvc.Razor", - "Microsoft.AspNetCore.Mvc.Razor.Extensions", "Microsoft.AspNetCore.Mvc.RazorPages", "Microsoft.AspNetCore.Mvc.TagHelpers", "Microsoft.AspNetCore.Mvc.ViewFeatures", @@ -154,7 +153,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts // Internal for unit testing internal static IEnumerable GetCandidateLibraries(DependencyContext dependencyContext) { - // When using Microsoft.AspNetCore.App \ Microsoft.AspNetCore.All shared runtimes, entries in the RuntimeLibraries + // When using the Microsoft.AspNetCore.App shared runtimes, entries in the RuntimeLibraries // get "erased" and it is no longer accurate to query to determine a library's dependency closure. // We'll use CompileLibraries to calculate the dependency graph and runtime library to resolve assemblies to inspect. var candidatesResolver = new CandidateResolver(dependencyContext.CompileLibraries, ReferenceAssemblies); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs index 29cf7cc085..df87c8d9f0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Authorization/AuthorizeFilter.cs @@ -8,9 +8,9 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization.Policy; +using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/DefaultEndpointConventionBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/DefaultEndpointConventionBuilder.cs new file mode 100644 index 0000000000..8427ba5c3b --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/DefaultEndpointConventionBuilder.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Routing; + +namespace Microsoft.AspNetCore.Builder +{ + internal class DefaultEndpointConventionBuilder : IEndpointConventionBuilder + { + public DefaultEndpointConventionBuilder() + { + Conventions = new List>(); + } + + public List> Conventions { get; } + + public void Apply(Action convention) + { + Conventions.Add(convention); + } + } +} \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs index 06e26ed407..2d873de87c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcApplicationBuilderExtensions.cs @@ -4,10 +4,9 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Internal; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -90,9 +89,7 @@ namespace Microsoft.AspNetCore.Builder if (options.Value.EnableEndpointRouting) { var mvcEndpointDataSource = app.ApplicationServices - .GetRequiredService>() - .OfType() - .First(); + .GetRequiredService(); var parameterPolicyFactory = app.ApplicationServices .GetRequiredService(); @@ -122,11 +119,21 @@ namespace Microsoft.AspNetCore.Builder } } + // Include all controllers with attribute routing and Razor pages + var defaultEndpointConventionBuilder = new DefaultEndpointConventionBuilder(); + mvcEndpointDataSource.AttributeRoutingConventionResolvers.Add((actionDescriptor) => + { + return defaultEndpointConventionBuilder; + }); + if (!app.Properties.TryGetValue(EndpointRoutingRegisteredKey, out _)) { // Matching middleware has not been registered yet // For back-compat register middleware so an endpoint is matched and then immediately used - app.UseEndpointRouting(); + app.UseEndpointRouting(routerBuilder => + { + routerBuilder.DataSources.Add(mvcEndpointDataSource); + }); } return app.UseEndpoint(); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcEndpointInfo.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcEndpointInfo.cs index 161189b871..5712fa6a55 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcEndpointInfo.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcEndpointInfo.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Routing.Patterns; namespace Microsoft.AspNetCore.Builder { - internal class MvcEndpointInfo + internal class MvcEndpointInfo : DefaultEndpointConventionBuilder { public MvcEndpointInfo( string name, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcEndpointRouteBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcEndpointRouteBuilderExtensions.cs new file mode 100644 index 0000000000..bef1b53372 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Builder/MvcEndpointRouteBuilderExtensions.cs @@ -0,0 +1,121 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Routing; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Builder +{ + public static class MvcEndpointRouteBuilderExtensions + { + public static IEndpointConventionBuilder MapApplication( + this IEndpointRouteBuilder routeBuilder) + { + return MapActionDescriptors(routeBuilder, null); + } + + public static IEndpointConventionBuilder MapAssembly( + this IEndpointRouteBuilder routeBuilder) + { + return MapActionDescriptors(routeBuilder, typeof(TContainingType)); + } + + private static IEndpointConventionBuilder MapActionDescriptors( + this IEndpointRouteBuilder routeBuilder, + Type containingType) + { + var mvcEndpointDataSource = routeBuilder.DataSources.OfType().FirstOrDefault(); + + if (mvcEndpointDataSource == null) + { + mvcEndpointDataSource = routeBuilder.ServiceProvider.GetRequiredService(); + routeBuilder.DataSources.Add(mvcEndpointDataSource); + } + + var conventionBuilder = new DefaultEndpointConventionBuilder(); + + var assemblyFilter = containingType?.Assembly; + + mvcEndpointDataSource.AttributeRoutingConventionResolvers.Add(actionDescriptor => + { + // Filter a descriptor by the assembly + // Note that this will only filter actions on controllers + // Does not support filtering Razor pages embedded in assemblies + if (assemblyFilter != null) + { + if (actionDescriptor is ControllerActionDescriptor controllerActionDescriptor) + { + if (controllerActionDescriptor.ControllerTypeInfo.Assembly != assemblyFilter) + { + return null; + } + } + } + + return conventionBuilder; + }); + + return conventionBuilder; + } + + public static IEndpointConventionBuilder MapControllerRoute( + this IEndpointRouteBuilder routeBuilder, + string name, + string template) + { + return MapControllerRoute(routeBuilder, name, template, defaults: null); + } + + public static IEndpointConventionBuilder MapControllerRoute( + this IEndpointRouteBuilder routeBuilder, + string name, + string template, + object defaults) + { + return MapControllerRoute(routeBuilder, name, template, defaults, constraints: null); + } + + public static IEndpointConventionBuilder MapControllerRoute( + this IEndpointRouteBuilder routeBuilder, + string name, + string template, + object defaults, + object constraints) + { + return MapControllerRoute(routeBuilder, name, template, defaults, constraints, dataTokens: null); + } + + public static IEndpointConventionBuilder MapControllerRoute( + this IEndpointRouteBuilder routeBuilder, + string name, + string template, + object defaults, + object constraints, + object dataTokens) + { + var mvcEndpointDataSource = routeBuilder.DataSources.OfType().FirstOrDefault(); + + if (mvcEndpointDataSource == null) + { + mvcEndpointDataSource = routeBuilder.ServiceProvider.GetRequiredService(); + routeBuilder.DataSources.Add(mvcEndpointDataSource); + } + + var endpointInfo = new MvcEndpointInfo( + name, + template, + new RouteValueDictionary(defaults), + new RouteValueDictionary(constraints), + new RouteValueDictionary(dataTokens), + routeBuilder.ServiceProvider.GetRequiredService()); + + mvcEndpointDataSource.ConventionalEndpointInfos.Add(endpointInfo); + + return endpointInfo; + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs index 7f7f0249ca..a0bcd94b00 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ChallengeResult.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs index 30a103a531..6893124313 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ConsumesAttribute.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Net.Http.Headers; using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs index 29c9ddab2d..6fd602d5c3 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ContentResult.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs index 3cc780746a..22078bb2a5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerBinderDelegate.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerBinderDelegate.cs similarity index 78% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerBinderDelegate.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerBinderDelegate.cs index 6a986160f0..dcfbe994f8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerBinderDelegate.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerBinderDelegate.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Controllers { - public delegate Task ControllerBinderDelegate( + internal delegate Task ControllerBinderDelegate( ControllerContext controllerContext, object controller, Dictionary arguments); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerBinderDelegateProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerBinderDelegateProvider.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerBinderDelegateProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerBinderDelegateProvider.cs index 20d600281e..bceb513944 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerBinderDelegateProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerBinderDelegateProvider.cs @@ -7,10 +7,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.ModelBinding; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Controllers { // Note: changes made to binding behavior in type should also be made to PageBinderFactory. - public static class ControllerBinderDelegateProvider + internal static class ControllerBinderDelegateProvider { public static ControllerBinderDelegate CreateBinderDelegate( ParameterBinder parameterBinder, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerFactoryProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerFactoryProvider.cs index 8b70db1f79..5c0ee05088 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerFactoryProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerFactoryProvider.cs @@ -5,11 +5,10 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; namespace Microsoft.AspNetCore.Mvc.Controllers { - public class ControllerFactoryProvider : IControllerFactoryProvider + internal class ControllerFactoryProvider : IControllerFactoryProvider { private readonly IControllerActivatorProvider _activatorProvider; private readonly Func _factoryCreateController; @@ -19,10 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers public ControllerFactoryProvider( IControllerActivatorProvider activatorProvider, IControllerFactory controllerFactory, -#pragma warning disable PUB0001 // Pubternal type in public API - IEnumerable propertyActivators -#pragma warning restore PUB0001 - ) + IEnumerable propertyActivators) { if (activatorProvider == null) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerActivator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerActivator.cs index 9de77f768c..9d40ddf8ef 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerActivator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerActivator.cs @@ -3,14 +3,14 @@ using System; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Infrastructure; namespace Microsoft.AspNetCore.Mvc.Controllers { /// /// that uses type activation to create controllers. /// - public class DefaultControllerActivator : IControllerActivator + internal class DefaultControllerActivator : IControllerActivator { private readonly ITypeActivatorCache _typeActivatorCache; @@ -18,9 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers /// Creates a new . /// /// The . -#pragma warning disable PUB0001 // Pubternal type in public API public DefaultControllerActivator(ITypeActivatorCache typeActivatorCache) -#pragma warning restore PUB0001 { if (typeActivatorCache == null) { @@ -31,7 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers } /// - public virtual object Create(ControllerContext controllerContext) + public object Create(ControllerContext controllerContext) { if (controllerContext == null) { @@ -59,7 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers } /// - public virtual void Release(ControllerContext context, object controller) + public void Release(ControllerContext context, object controller) { if (context == null) { @@ -71,8 +69,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers throw new ArgumentNullException(nameof(controller)); } - var disposable = controller as IDisposable; - if (disposable != null) + if (controller is IDisposable disposable) { disposable.Dispose(); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs index 8c10083810..065b8ebc5c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerFactory.cs @@ -5,14 +5,13 @@ using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; namespace Microsoft.AspNetCore.Mvc.Controllers { /// /// Default implementation for . /// - public class DefaultControllerFactory : IControllerFactory + internal class DefaultControllerFactory : IControllerFactory { private readonly IControllerActivator _controllerActivator; private readonly IControllerPropertyActivator[] _propertyActivators; @@ -29,10 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers /// public DefaultControllerFactory( IControllerActivator controllerActivator, -#pragma warning disable PUB0001 // Pubternal type in public API - IEnumerable propertyActivators -#pragma warning restore PUB0001 - ) + IEnumerable propertyActivators) { if (controllerActivator == null) { @@ -48,13 +44,8 @@ namespace Microsoft.AspNetCore.Mvc.Controllers _propertyActivators = propertyActivators.ToArray(); } - /// - /// The used to create a controller. - /// - protected IControllerActivator ControllerActivator => _controllerActivator; - /// - public virtual object CreateController(ControllerContext context) + public object CreateController(ControllerContext context) { if (context == null) { @@ -78,7 +69,7 @@ namespace Microsoft.AspNetCore.Mvc.Controllers } /// - public virtual void ReleaseController(ControllerContext context, object controller) + public void ReleaseController(ControllerContext context, object controller) { if (context == null) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultControllerPropertyActivator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerPropertyActivator.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultControllerPropertyActivator.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerPropertyActivator.cs index 857a4b23cb..20f0b74ecc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultControllerPropertyActivator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/DefaultControllerPropertyActivator.cs @@ -6,13 +6,12 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading; -using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Controllers { - public class DefaultControllerPropertyActivator : IControllerPropertyActivator + internal class DefaultControllerPropertyActivator : IControllerPropertyActivator { private static readonly Func[]> _getPropertiesToActivate = GetPropertiesToActivate; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IControllerPropertyActivatorFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/IControllerPropertyActivatorFactory.cs similarity index 73% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IControllerPropertyActivatorFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/IControllerPropertyActivatorFactory.cs index 441dee9898..95d9cff4a5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IControllerPropertyActivatorFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Controllers/IControllerPropertyActivatorFactory.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Controllers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Controllers { - public interface IControllerPropertyActivator + internal interface IControllerPropertyActivator { void Activate(ControllerContext context, object controller); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApiBehaviorOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/ApiBehaviorOptionsSetup.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApiBehaviorOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/ApiBehaviorOptionsSetup.cs index 02ae3bc30d..6203729684 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ApiBehaviorOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/ApiBehaviorOptionsSetup.cs @@ -4,14 +4,15 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.Extensions.DependencyInjection { - public class ApiBehaviorOptionsSetup : + internal class ApiBehaviorOptionsSetup : ConfigureCompatibilityOptions, IConfigureOptions { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcBuilder.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcBuilder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcBuilder.cs index d2a0db532e..2a339145df 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcBuilder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcBuilder.cs @@ -3,14 +3,13 @@ using System; using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// Allows fine grained configuration of MVC services. /// - public class MvcBuilder : IMvcBuilder + internal class MvcBuilder : IMvcBuilder { /// /// Initializes a new instance. @@ -39,4 +38,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// public ApplicationPartManager PartManager { get; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreBuilder.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreBuilder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreBuilder.cs index 89a9897afd..b6674f6520 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreBuilder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreBuilder.cs @@ -3,14 +3,13 @@ using System; using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// Allows fine grained configuration of essential MVC services. /// - public class MvcCoreBuilder : IMvcCoreBuilder + internal class MvcCoreBuilder : IMvcCoreBuilder { /// /// Initializes a new instance. @@ -41,4 +40,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// public IServiceCollection Services { get; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs index 57499c930a..37677903ef 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreMvcCoreBuilderExtensions.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreRouteOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreRouteOptionsSetup.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreRouteOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreRouteOptionsSetup.cs index 6ed400f506..85af370d9f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreRouteOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreRouteOptionsSetup.cs @@ -6,12 +6,12 @@ using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// Sets up MVC default options for . /// - public class MvcCoreRouteOptionsSetup : IConfigureOptions + internal class MvcCoreRouteOptionsSetup : IConfigureOptions { /// /// Configures the . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs index 95a4afb21b..8ea71b7178 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; @@ -159,7 +158,7 @@ namespace Microsoft.Extensions.DependencyInjection // Action Discovery // // These are consumed only when creating action descriptors, then they can be deallocated - + services.TryAddSingleton(); services.TryAddEnumerable( ServiceDescriptor.Transient()); services.TryAddEnumerable( @@ -270,8 +269,7 @@ namespace Microsoft.Extensions.DependencyInjection // // Endpoint Routing / Endpoints // - services.TryAddEnumerable( - ServiceDescriptor.Singleton()); + services.TryAddSingleton(); services.TryAddSingleton(); // diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcMarkerService.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcMarkerService.cs similarity index 74% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcMarkerService.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcMarkerService.cs index c2eb80ada2..337a1baca5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcMarkerService.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcMarkerService.cs @@ -1,15 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Extensions.DependencyInjection; - -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// A marker class used to determine if all the MVC services were added /// to the before MVC is configured. /// - public class MvcMarkerService + internal class MvcMarkerService { } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DisableRequestSizeLimitAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DisableRequestSizeLimitAttribute.cs index b92092667e..0c327e28a6 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DisableRequestSizeLimitAttribute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DisableRequestSizeLimitAttribute.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs index 99385c9bd3..0c33859001 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileContentResult.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs index 486069a5ea..59f0348e78 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/FileStreamResult.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ControllerActionFilter.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ControllerActionFilter.cs index 93e4c4774a..c169d8173c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ControllerActionFilter.cs @@ -4,14 +4,13 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A filter implementation which delegates to the controller for action filter interfaces. /// - public class ControllerActionFilter : IAsyncActionFilter, IOrderedFilter + internal class ControllerActionFilter : IAsyncActionFilter, IOrderedFilter { // Controller-filter methods run farthest from the action by default. /// @@ -55,7 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } private static async Task ExecuteActionFilter( - ActionExecutingContext context, + ActionExecutingContext context, ActionExecutionDelegate next, IActionFilter actionFilter) { @@ -66,4 +65,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerResultFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ControllerResultFilter.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerResultFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ControllerResultFilter.cs index 3e30debccc..3352c92a9d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerResultFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ControllerResultFilter.cs @@ -4,14 +4,13 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A filter implementation which delegates to the controller for result filter interfaces. /// - public class ControllerResultFilter : IAsyncResultFilter, IOrderedFilter + internal class ControllerResultFilter : IAsyncResultFilter, IOrderedFilter { // Controller-filter methods run farthest from the result by default. /// @@ -66,4 +65,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultFilterProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/DefaultFilterProvider.cs similarity index 84% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultFilterProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/DefaultFilterProvider.cs index 3e7f685494..03c7c62004 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultFilterProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/DefaultFilterProvider.cs @@ -4,11 +4,10 @@ using System; using System.Diagnostics; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public class DefaultFilterProvider : IFilterProvider + internal class DefaultFilterProvider : IFilterProvider { public int Order => -1000; @@ -35,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal { } - public virtual void ProvideFilter(FilterProviderContext context, FilterItem filterItem) + public void ProvideFilter(FilterProviderContext context, FilterItem filterItem) { if (filterItem.Filter != null) { @@ -44,8 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = filterItem.Descriptor.Filter; - var filterFactory = filter as IFilterFactory; - if (filterFactory == null) + if (!(filter is IFilterFactory filterFactory)) { filterItem.Filter = filter; filterItem.IsReusable = true; @@ -72,9 +70,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal Debug.Assert(actualFilter != null, "actualFilter should not be null"); Debug.Assert(filterMetadata != null, "filterMetadata should not be null"); - var container = actualFilter as IFilterContainer; - - if (container != null) + if (actualFilter is IFilterContainer container) { container.FilterDefinition = filterMetadata; } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DisableRequestSizeLimitFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/DisableRequestSizeLimitFilter.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DisableRequestSizeLimitFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/DisableRequestSizeLimitFilter.cs index 51595bbaa6..75818a6373 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DisableRequestSizeLimitFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/DisableRequestSizeLimitFilter.cs @@ -3,16 +3,15 @@ using System; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A filter that sets /// to null. /// - public class DisableRequestSizeLimitFilter : IAuthorizationFilter, IRequestSizePolicy + internal class DisableRequestSizeLimitFilter : IAuthorizationFilter, IRequestSizePolicy { private readonly ILogger _logger; @@ -29,8 +28,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// to null. /// /// The . - /// If is not enabled or is read-only, - /// the is not applied. + /// If is not enabled or is read-only, + /// the is not applied. public void OnAuthorization(AuthorizationFilterContext context) { if (context == null) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterCursor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterCursor.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterCursor.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterCursor.cs index b297712bd0..73caf18f3f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterCursor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterCursor.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A one-way cursor for filters. @@ -25,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// Result /// /// - public struct FilterCursor + internal struct FilterCursor { private readonly IFilterMetadata[] _filters; private int _index; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterCursorItem.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterCursorItem.cs similarity index 79% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterCursorItem.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterCursorItem.cs index a62aa1b8cc..c925d49ab2 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterCursorItem.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterCursorItem.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public readonly struct FilterCursorItem + internal readonly struct FilterCursorItem { public FilterCursorItem(TFilter filter, TFilterAsync filterAsync) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterDescriptorOrderComparer.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterDescriptorOrderComparer.cs similarity index 88% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterDescriptorOrderComparer.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterDescriptorOrderComparer.cs index daadc073d4..1e43ed8280 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterDescriptorOrderComparer.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterDescriptorOrderComparer.cs @@ -5,9 +5,9 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public class FilterDescriptorOrderComparer : IComparer + internal class FilterDescriptorOrderComparer : IComparer { public static FilterDescriptorOrderComparer Comparer { get; } = new FilterDescriptorOrderComparer(); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterFactory.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterFactory.cs index 4f53acfef5..cc7563703b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterFactory.cs @@ -4,11 +4,10 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public static class FilterFactory + internal static class FilterFactory { public static FilterFactoryResult GetAllFilters( IFilterProvider[] filterProviders, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterFactoryResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterFactoryResult.cs similarity index 79% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterFactoryResult.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterFactoryResult.cs index 69e39cfea9..2f03f4d305 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/FilterFactoryResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/FilterFactoryResult.cs @@ -1,11 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public readonly struct FilterFactoryResult + internal readonly struct FilterFactoryResult { public FilterFactoryResult( FilterItem[] cacheableFilters, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IMiddlewareFilterFeature.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/IMiddlewareFilterFeature.cs similarity index 83% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IMiddlewareFilterFeature.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/IMiddlewareFilterFeature.cs index 43af488b8a..cc9bcd38af 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IMiddlewareFilterFeature.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/IMiddlewareFilterFeature.cs @@ -1,19 +1,17 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A feature in which is used to capture the /// currently executing context of a resource filter. This feature is used in the final middleware /// of a middleware filter's pipeline to keep the request flow through the rest of the MVC layers. /// - public interface IMiddlewareFilterFeature + internal interface IMiddlewareFilterFeature { ResourceExecutingContext ResourceExecutingContext { get; } ResourceExecutionDelegate ResourceExecutionDelegate { get; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IResponseCacheFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/IResponseCacheFilter.cs similarity index 67% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IResponseCacheFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/IResponseCacheFilter.cs index 5b53c254dd..9d43079624 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IResponseCacheFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/IResponseCacheFilter.cs @@ -1,14 +1,12 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A filter which sets the appropriate headers related to Response caching. /// - public interface IResponseCacheFilter : IFilterMetadata + internal interface IResponseCacheFilter : IFilterMetadata { } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilter.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilter.cs index 11ac93d5ab..d84bd188c8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilter.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A filter which executes a user configured middleware pipeline. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs index 019f1551f3..be4b3f8270 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterAttribute.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterBuilder.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterBuilder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterBuilder.cs index 6257968f90..de689d3e2c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterBuilder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterBuilder.cs @@ -7,12 +7,12 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// Builds a middleware pipeline after receiving the pipeline from a pipeline provider /// - public class MiddlewareFilterBuilder + internal class MiddlewareFilterBuilder { // 'GetOrAdd' call on the dictionary is not thread safe and we might end up creating the pipeline more // once. To prevent this Lazy<> is used. In the worst case multiple Lazy<> objects are created for multiple diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterBuilderStartupFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterBuilderStartupFilter.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterBuilderStartupFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterBuilderStartupFilter.cs index d568da7b51..563942e57c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterBuilderStartupFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterBuilderStartupFilter.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { internal class MiddlewareFilterBuilderStartupFilter : IStartupFilter { @@ -23,4 +23,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterConfigurationProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterConfigurationProvider.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterConfigurationProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterConfigurationProvider.cs index ca05f4d6df..a22b126333 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterConfigurationProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterConfigurationProvider.cs @@ -8,13 +8,13 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// Calls into user provided 'Configure' methods for configuring a middleware pipeline. The semantics of finding /// the 'Configure' methods is similar to the application Startup class. /// - public class MiddlewareFilterConfigurationProvider + internal class MiddlewareFilterConfigurationProvider { public Action CreateConfigureDelegate(Type configurationType) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterFeature.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterFeature.cs similarity index 69% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterFeature.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterFeature.cs index d33378d6f7..7a0da41b91 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MiddlewareFilterFeature.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/MiddlewareFilterFeature.cs @@ -1,11 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.Filters; - -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public class MiddlewareFilterFeature : IMiddlewareFilterFeature + internal class MiddlewareFilterFeature : IMiddlewareFilterFeature { public ResourceExecutingContext ResourceExecutingContext { get; set; } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RequestFormLimitsFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/RequestFormLimitsFilter.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RequestFormLimitsFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/RequestFormLimitsFilter.cs index c60e7e2ea2..175e888d95 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RequestFormLimitsFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/RequestFormLimitsFilter.cs @@ -3,15 +3,14 @@ using System; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A filter that configures for the current request. /// - public class RequestFormLimitsFilter : IAuthorizationFilter, IRequestFormLimitsPolicy + internal class RequestFormLimitsFilter : IAuthorizationFilter, IRequestFormLimitsPolicy { private readonly ILogger _logger; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RequestSizeLimitFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/RequestSizeLimitFilter.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RequestSizeLimitFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/RequestSizeLimitFilter.cs index c5653f99a5..7cc2390c23 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RequestSizeLimitFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/RequestSizeLimitFilter.cs @@ -3,16 +3,15 @@ using System; using Microsoft.AspNetCore.Http.Features; -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// - /// A filter that sets the + /// A filter that sets the /// to the specified . /// - public class RequestSizeLimitFilter : IAuthorizationFilter, IRequestSizePolicy + internal class RequestSizeLimitFilter : IAuthorizationFilter, IRequestSizePolicy { private readonly ILogger _logger; @@ -30,7 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// Sets the to . /// /// The . - /// If is not enabled or is read-only, + /// If is not enabled or is read-only, /// the is not applied. public void OnAuthorization(AuthorizationFilterContext context) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ResponseCacheFilter.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ResponseCacheFilter.cs index 55d63fc975..8996ff90de 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ResponseCacheFilter.cs @@ -2,15 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// An which sets the appropriate headers related to response caching. /// - public class ResponseCacheFilter : IActionFilter, IResponseCacheFilter + internal class ResponseCacheFilter : IActionFilter, IResponseCacheFilter { private readonly ResponseCacheFilterExecutor _executor; private readonly ILogger _logger; @@ -105,4 +104,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal { } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilterExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ResponseCacheFilterExecutor.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilterExecutor.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ResponseCacheFilterExecutor.cs index 02100b838e..cdff970483 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseCacheFilterExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Filters/ResponseCacheFilterExecutor.cs @@ -2,16 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.ResponseCaching; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public class ResponseCacheFilterExecutor + internal class ResponseCacheFilterExecutor { private readonly CacheProfile _cacheProfile; private int? _cacheDuration; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs index b967d74c08..78e4fc1274 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ForbidResult.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/AcceptHeaderParser.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/AcceptHeaderParser.cs index 289e151226..16e26b2165 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AcceptHeaderParser.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/AcceptHeaderParser.cs @@ -5,9 +5,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; -namespace Microsoft.AspNetCore.Mvc.Formatters.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { - public static class AcceptHeaderParser + internal static class AcceptHeaderParser { public static IList ParseAcceptHeader(IList acceptHeaders) { @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Internal } // We deliberately want to ignore media types that we are not capable of parsing. - // This is due to the fact that some browsers will send invalid media types like + // This is due to the fact that some browsers will send invalid media types like // ; q=0.9 or */;q=0.2, etc. // In this scenario, our recovery action consists of advancing the pointer to the // next separator and moving on. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs index e70f0130c9..5ba22953e5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs @@ -6,8 +6,6 @@ using System.Globalization; using System.Linq; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Formatters.Internal; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpParseResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/HttpParseResult.cs similarity index 73% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpParseResult.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/HttpParseResult.cs index 84e76f08d4..71b0f57a7e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpParseResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/HttpParseResult.cs @@ -1,9 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Mvc.Formatters.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { - public enum HttpParseResult + internal enum HttpParseResult { Parsed, NotParsed, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpTokenParsingRules.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/HttpTokenParsingRules.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpTokenParsingRules.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/HttpTokenParsingRules.cs index a93f26d916..1f478eb564 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/HttpTokenParsingRules.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/HttpTokenParsingRules.cs @@ -4,9 +4,9 @@ using System.Diagnostics.Contracts; using System.Text; -namespace Microsoft.AspNetCore.Mvc.Formatters.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { - public static class HttpTokenParsingRules + internal static class HttpTokenParsingRules { private static readonly bool[] TokenChars; private const int MaxNestedCount = 5; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IFormatFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/IFormatFilter.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IFormatFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/IFormatFilter.cs index 911ca2d247..185b0cfb3c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/IFormatFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/IFormatFilter.cs @@ -3,12 +3,12 @@ using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Formatters.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { /// /// A filter that produces the desired content type for the request. /// - public interface IFormatFilter : IFilterMetadata + internal interface IFormatFilter : IFilterMetadata { /// /// Gets the format value for the request associated with the provided . @@ -17,4 +17,4 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Internal /// A format value, or null if a format cannot be determined for the request. string GetFormat(ActionContext context); } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs index 7c557ed4cc..8e7103d588 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaType.cs @@ -5,7 +5,6 @@ using System; using System.Globalization; using System.Text; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Formatters.Internal; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Mvc.Formatters @@ -393,9 +392,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// The media type to parse. /// The position at which the parsing starts. /// The parsed media type with its associated quality. -#pragma warning disable PUB0001 // Pubternal type in public API public static MediaTypeSegmentWithQuality CreateMediaTypeSegmentWithQuality(string mediaType, int start) -#pragma warning restore PUB0001 { var parsedMediaType = new MediaType(mediaType, start, length: null); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MediaTypeSegmentWithQuality.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaTypeSegmentWithQuality.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MediaTypeSegmentWithQuality.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaTypeSegmentWithQuality.cs index 52d6281ed1..66714ae17b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MediaTypeSegmentWithQuality.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/MediaTypeSegmentWithQuality.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.Formatters.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { /// /// A media type with its associated quality. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseContentTypeHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/ResponseContentTypeHelper.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseContentTypeHelper.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/ResponseContentTypeHelper.cs index 936ef92973..cc6dde7a08 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResponseContentTypeHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Formatters/ResponseContentTypeHelper.cs @@ -4,11 +4,10 @@ using System.Diagnostics; using System.Text; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Formatters; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { - public static class ResponseContentTypeHelper + internal static class ResponseContentTypeHelper { /// /// Gets the content type and encoding that need to be used for the response. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionInvokerFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionInvokerFactory.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionInvokerFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionInvokerFactory.cs index b654ea26a8..58b08b4b31 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionInvokerFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionInvokerFactory.cs @@ -4,11 +4,10 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Abstractions; -using Microsoft.AspNetCore.Mvc.Infrastructure; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class ActionInvokerFactory : IActionInvokerFactory + internal class ActionInvokerFactory : IActionInvokerFactory { private readonly IActionInvokerProvider[] _actionInvokerProviders; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionMethodExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionMethodExecutor.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionMethodExecutor.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionMethodExecutor.cs index 806b97d1e5..3829e404de 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionMethodExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionMethodExecutor.cs @@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { internal abstract class ActionMethodExecutor { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionResultTypeMapper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionResultTypeMapper.cs similarity index 84% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionResultTypeMapper.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionResultTypeMapper.cs index 82f1d02998..de9a74eeb4 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionResultTypeMapper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionResultTypeMapper.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Infrastructure; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class ActionResultTypeMapper : IActionResultTypeMapper + internal class ActionResultTypeMapper : IActionResultTypeMapper { public Type GetResultDataType(Type returnType) { @@ -15,7 +14,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal throw new ArgumentNullException(nameof(returnType)); } - if (returnType.IsGenericType && + if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(ActionResult<>)) { return returnType.GetGenericArguments()[0]; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionSelector.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionSelector.cs index 5dba1a7654..834862f568 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ActionSelector.cs @@ -15,12 +15,12 @@ using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// /// A default implementation. /// - public class ActionSelector : IActionSelector + internal class ActionSelector : IActionSelector { private static readonly IReadOnlyList EmptyActions = Array.Empty(); @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// The set of actions that satisfy all constraints. /// A list of the best matching actions. - protected virtual IReadOnlyList SelectBestActions(IReadOnlyList actions) + private IReadOnlyList SelectBestActions(IReadOnlyList actions) { return actions; } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AmbiguousActionException.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/AmbiguousActionException.cs similarity index 83% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AmbiguousActionException.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/AmbiguousActionException.cs index 6b1a34d893..afe28c0209 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AmbiguousActionException.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/AmbiguousActionException.cs @@ -4,13 +4,13 @@ using System; using System.Runtime.Serialization; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// /// An exception which indicates multiple matches in action selection. /// [Serializable] - public class AmbiguousActionException : InvalidOperationException + internal class AmbiguousActionException : InvalidOperationException { public AmbiguousActionException(string message) : base(message) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ClientErrorResultFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ClientErrorResultFilter.cs index 1ef66b1a33..b9babd87a0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ClientErrorResultFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ClientErrorResultFilter.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Infrastructure diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ContentResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ContentResultExecutor.cs index 7a1f333b3a..f73e1b72ea 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ContentResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ContentResultExecutor.cs @@ -2,9 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Infrastructure @@ -36,14 +35,12 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure var response = context.HttpContext.Response; - string resolvedContentType; - Encoding resolvedContentTypeEncoding; ResponseContentTypeHelper.ResolveContentTypeAndEncoding( result.ContentType, response.ContentType, DefaultContentType, - out resolvedContentType, - out resolvedContentTypeEncoding); + out var resolvedContentType, + out var resolvedContentTypeEncoding); response.ContentType = resolvedContentType; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvoker.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvoker.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvoker.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvoker.cs index 767ed08505..099797fbe8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvoker.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvoker.cs @@ -8,14 +8,13 @@ using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class ControllerActionInvoker : ResourceInvoker, IActionInvoker + internal class ControllerActionInvoker : ResourceInvoker, IActionInvoker { private readonly ControllerActionInvokerCacheEntry _cacheEntry; private readonly ControllerContext _controllerContext; @@ -27,12 +26,12 @@ namespace Microsoft.AspNetCore.Mvc.Internal internal ControllerActionInvoker( ILogger logger, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper, ControllerContext controllerContext, ControllerActionInvokerCacheEntry cacheEntry, IFilterMetadata[] filters) - : base(diagnosticSource, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories) + : base(diagnosticListener, logger, mapper, controllerContext, filters, controllerContext.ValueProviderFactories) { if (cacheEntry == null) { @@ -115,7 +114,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IAsyncActionFilter)state; var actionExecutingContext = _actionExecutingContext; - _diagnosticSource.BeforeOnActionExecution(actionExecutingContext, filter); + _diagnosticListener.BeforeOnActionExecution(actionExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( MvcCoreLoggerExtensions.ActionFilter, nameof(IAsyncActionFilter.OnActionExecutionAsync), @@ -153,7 +152,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal }; } - _diagnosticSource.AfterOnActionExecution(_actionExecutedContext, filter); + _diagnosticListener.AfterOnActionExecution(_actionExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( MvcCoreLoggerExtensions.ActionFilter, nameof(IAsyncActionFilter.OnActionExecutionAsync), @@ -170,7 +169,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IActionFilter)state; var actionExecutingContext = _actionExecutingContext; - _diagnosticSource.BeforeOnActionExecuting(actionExecutingContext, filter); + _diagnosticListener.BeforeOnActionExecuting(actionExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( MvcCoreLoggerExtensions.ActionFilter, nameof(IActionFilter.OnActionExecuting), @@ -178,7 +177,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnActionExecuting(actionExecutingContext); - _diagnosticSource.AfterOnActionExecuting(actionExecutingContext, filter); + _diagnosticListener.AfterOnActionExecuting(actionExecutingContext, filter); _logger.AfterExecutingMethodOnFilter( MvcCoreLoggerExtensions.ActionFilter, nameof(IActionFilter.OnActionExecuting), @@ -220,7 +219,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IActionFilter)state; var actionExecutedContext = _actionExecutedContext; - _diagnosticSource.BeforeOnActionExecuted(actionExecutedContext, filter); + _diagnosticListener.BeforeOnActionExecuted(actionExecutedContext, filter); _logger.BeforeExecutingMethodOnFilter( MvcCoreLoggerExtensions.ActionFilter, nameof(IActionFilter.OnActionExecuted), @@ -228,7 +227,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnActionExecuted(actionExecutedContext); - _diagnosticSource.AfterOnActionExecuted(actionExecutedContext, filter); + _diagnosticListener.AfterOnActionExecuted(actionExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( MvcCoreLoggerExtensions.ActionFilter, nameof(IActionFilter.OnActionExecuted), @@ -336,13 +335,13 @@ namespace Microsoft.AspNetCore.Mvc.Internal var actionMethodExecutor = _cacheEntry.ActionMethodExecutor; var orderedArguments = PrepareArguments(arguments, objectMethodExecutor); - var diagnosticSource = _diagnosticSource; + var diagnosticListener = _diagnosticListener; var logger = _logger; IActionResult result = null; try { - diagnosticSource.BeforeActionMethod( + diagnosticListener.BeforeActionMethod( controllerContext, arguments, controller); @@ -363,7 +362,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } finally { - diagnosticSource.AfterActionMethod( + diagnosticListener.AfterActionMethod( controllerContext, arguments, controllerContext, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCache.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerCache.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCache.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerCache.cs index 0c6bd2adc1..e7628769e4 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCache.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerCache.cs @@ -12,9 +12,9 @@ using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class ControllerActionInvokerCache + internal class ControllerActionInvokerCache { private readonly IActionDescriptorCollectionProvider _collectionProvider; private readonly ParameterBinder _parameterBinder; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCacheEntry.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerCacheEntry.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCacheEntry.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerCacheEntry.cs index 6b06f0e02b..17810cf866 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerCacheEntry.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerCacheEntry.cs @@ -2,12 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class ControllerActionInvokerCacheEntry + internal class ControllerActionInvokerCacheEntry { internal ControllerActionInvokerCacheEntry( FilterItem[] cachedFilters, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerProvider.cs similarity index 88% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerProvider.cs index b9b135ff52..b05bd104dd 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvokerProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ControllerActionInvokerProvider.cs @@ -7,34 +7,33 @@ using System.Diagnostics; using System.Linq; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Controllers; -using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class ControllerActionInvokerProvider : IActionInvokerProvider + internal class ControllerActionInvokerProvider : IActionInvokerProvider { private readonly ControllerActionInvokerCache _controllerActionInvokerCache; private readonly IReadOnlyList _valueProviderFactories; private readonly int _maxModelValidationErrors; private readonly ILogger _logger; - private readonly DiagnosticSource _diagnosticSource; + private readonly DiagnosticListener _diagnosticListener; private readonly IActionResultTypeMapper _mapper; public ControllerActionInvokerProvider( ControllerActionInvokerCache controllerActionInvokerCache, IOptions optionsAccessor, ILoggerFactory loggerFactory, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, IActionResultTypeMapper mapper) { _controllerActionInvokerCache = controllerActionInvokerCache; _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray(); _maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors; _logger = loggerFactory.CreateLogger(); - _diagnosticSource = diagnosticSource; + _diagnosticListener = diagnosticListener; _mapper = mapper; } @@ -59,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var invoker = new ControllerActionInvoker( _logger, - _diagnosticSource, + _diagnosticListener, _mapper, controllerContext, cacheResult.cacheEntry, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/CopyOnWriteList.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/CopyOnWriteList.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/CopyOnWriteList.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/CopyOnWriteList.cs index a051b69cff..44252104de 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/CopyOnWriteList.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/CopyOnWriteList.cs @@ -4,9 +4,9 @@ using System.Collections; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public class CopyOnWriteList : IList + internal class CopyOnWriteList : IList { private readonly IReadOnlyList _source; private List _copy; @@ -16,9 +16,9 @@ namespace Microsoft.AspNetCore.Mvc.Internal _source = source; } - protected IReadOnlyList Readable => _copy ?? _source; + private IReadOnlyList Readable => _copy ?? _source; - protected List Writable + private List Writable { get { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/DefaultOutputFormatterSelector.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/DefaultOutputFormatterSelector.cs index 61a62ec63f..bafe6d239d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/DefaultOutputFormatterSelector.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/DefaultOutputFormatterSelector.cs @@ -7,8 +7,6 @@ using System.Collections.ObjectModel; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.AspNetCore.Mvc.Formatters.Internal; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileContentResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileContentResultExecutor.cs index 6d194c52f8..e4c2aef2c2 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileContentResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileContentResultExecutor.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs index 8c2ecb98a2..bfd5546bed 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileResultExecutorBase.cs @@ -10,7 +10,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Http.Headers; using Microsoft.AspNetCore.Internal; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileStreamResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileStreamResultExecutor.cs index 6cb300eff1..df3a6feb28 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileStreamResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/FileStreamResultExecutor.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionSelector.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionSelector.cs index 30c9902e7d..d372b39d8b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionSelector.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IActionSelector.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure /// The associated with the current request. /// The set of candidates. /// The best candidate for the current request or null. - /// + /// /// Thrown when action selection results in an ambiguity. /// /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ITypeActivatorCache.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ITypeActivatorCache.cs similarity index 70% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ITypeActivatorCache.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ITypeActivatorCache.cs index a097b29910..d5487d9425 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ITypeActivatorCache.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ITypeActivatorCache.cs @@ -3,13 +3,13 @@ using System; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// - /// Caches instances produced by - /// . + /// Caches instances produced by + /// . /// - public interface ITypeActivatorCache + internal interface ITypeActivatorCache { /// /// Creates an instance of . @@ -19,4 +19,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// The of the to create. TInstance CreateInstance(IServiceProvider serviceProvider, Type optionType); } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/LocalRedirectResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/LocalRedirectResultExecutor.cs index 9ae7a3bda5..e44d5deb97 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/LocalRedirectResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/LocalRedirectResultExecutor.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MemoryPoolHttpRequestStreamReaderFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MemoryPoolHttpRequestStreamReaderFactory.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MemoryPoolHttpRequestStreamReaderFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MemoryPoolHttpRequestStreamReaderFactory.cs index 88f6f8428c..aff1df69a9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MemoryPoolHttpRequestStreamReaderFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MemoryPoolHttpRequestStreamReaderFactory.cs @@ -5,15 +5,14 @@ using System; using System.Buffers; using System.IO; using System.Text; -using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.WebUtilities; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// /// An that uses pooled buffers. /// - public class MemoryPoolHttpRequestStreamReaderFactory : IHttpRequestStreamReaderFactory + internal class MemoryPoolHttpRequestStreamReaderFactory : IHttpRequestStreamReaderFactory { /// /// The default size of created char buffers. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MemoryPoolHttpResponseStreamWriterFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MemoryPoolHttpResponseStreamWriterFactory.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MemoryPoolHttpResponseStreamWriterFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MemoryPoolHttpResponseStreamWriterFactory.cs index 91dd31e0c7..56978067c5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MemoryPoolHttpResponseStreamWriterFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MemoryPoolHttpResponseStreamWriterFactory.cs @@ -5,15 +5,14 @@ using System; using System.Buffers; using System.IO; using System.Text; -using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.WebUtilities; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// /// An that uses pooled buffers. /// - public class MemoryPoolHttpResponseStreamWriterFactory : IHttpResponseStreamWriterFactory + internal class MemoryPoolHttpResponseStreamWriterFactory : IHttpResponseStreamWriterFactory { /// /// The default size of buffers s will allocate. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilter.cs index c535bb118b..2cfc4ec773 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilter.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Infrastructure diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilterFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilterFactory.cs index 3f5c81dc98..6fe848ae9e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilterFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ModelStateInvalidFilterFactory.cs @@ -9,7 +9,7 @@ using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Mvc.Infrastructure { - internal sealed class ModelStateInvalidFilterFactory : IFilterFactory, IOrderedFilter + internal class ModelStateInvalidFilterFactory : IFilterFactory, IOrderedFilter { public int Order => ModelStateInvalidFilter.FilterOrder; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MvcCoreMvcOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MvcCoreMvcOptionsSetup.cs index 7b89b69ee6..81ba0b2ace 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MvcCoreMvcOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/MvcCoreMvcOptionsSetup.cs @@ -8,7 +8,6 @@ using System.Threading; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NonDisposableStream.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/NonDisposableStream.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NonDisposableStream.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/NonDisposableStream.cs index 9cc9a46ea4..a5260ae63b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NonDisposableStream.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/NonDisposableStream.cs @@ -6,14 +6,14 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// /// Stream that delegates to an inner stream. /// This Stream is present so that the inner stream is not closed /// even when Close() or Dispose() is called. /// - public class NonDisposableStream : Stream + internal class NonDisposableStream : Stream { private readonly Stream _innerStream; @@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// The inner stream this object delegates to. /// - protected Stream InnerStream => _innerStream; + private Stream InnerStream => _innerStream; /// public override bool CanRead => _innerStream.CanRead; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ObjectResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ObjectResultExecutor.cs index d48d213532..6c5179d222 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ObjectResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ObjectResultExecutor.cs @@ -9,7 +9,6 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Infrastructure diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ParameterDefaultValues.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ParameterDefaultValues.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ParameterDefaultValues.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ParameterDefaultValues.cs index 8263da1650..b7259fc9b7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ParameterDefaultValues.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ParameterDefaultValues.cs @@ -6,9 +6,9 @@ using System.ComponentModel; using System.Reflection; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public static class ParameterDefaultValues + internal static class ParameterDefaultValues { public static object[] GetParameterDefaultValues(MethodInfo methodInfo) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/PhysicalFileResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/PhysicalFileResultExecutor.cs index fa4757212d..1702e2b340 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/PhysicalFileResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/PhysicalFileResultExecutor.cs @@ -7,7 +7,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectResultExecutor.cs index e8f80b17da..8a480cc237 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectResultExecutor.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToActionResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToActionResultExecutor.cs index b1b131274b..187968c1af 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToActionResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToActionResultExecutor.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToPageResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToPageResultExecutor.cs index ee1c060e87..3e87985983 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToPageResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToPageResultExecutor.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToRouteResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToRouteResultExecutor.cs index 04e15feacf..268ddd37cc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToRouteResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/RedirectToRouteResultExecutor.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResourceInvoker.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ResourceInvoker.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResourceInvoker.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ResourceInvoker.cs index 2b73da1c0f..ff969d90b0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ResourceInvoker.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/ResourceInvoker.cs @@ -8,16 +8,15 @@ using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { - public abstract class ResourceInvoker + internal abstract class ResourceInvoker { - protected readonly DiagnosticSource _diagnosticSource; + protected readonly DiagnosticListener _diagnosticListener; protected readonly ILogger _logger; protected readonly IActionResultTypeMapper _mapper; protected readonly ActionContext _actionContext; @@ -38,14 +37,14 @@ namespace Microsoft.AspNetCore.Mvc.Internal protected object _instance; public ResourceInvoker( - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, ILogger logger, IActionResultTypeMapper mapper, ActionContext actionContext, IFilterMetadata[] filters, IList valueProviderFactories) { - _diagnosticSource = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource)); + _diagnosticListener = diagnosticListener ?? throw new ArgumentNullException(nameof(diagnosticListener)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _actionContext = actionContext ?? throw new ArgumentNullException(nameof(actionContext)); @@ -59,7 +58,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal { try { - _diagnosticSource.BeforeAction( + _diagnosticListener.BeforeAction( _actionContext.ActionDescriptor, _actionContext.HttpContext, _actionContext.RouteData); @@ -89,7 +88,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } finally { - _diagnosticSource.AfterAction( + _diagnosticListener.AfterAction( _actionContext.ActionDescriptor, _actionContext.HttpContext, _actionContext.RouteData); @@ -130,7 +129,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal { var actionContext = _actionContext; - _diagnosticSource.BeforeActionResult(actionContext, result); + _diagnosticListener.BeforeActionResult(actionContext, result); _logger.BeforeExecutingActionResult(result); try @@ -139,7 +138,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } finally { - _diagnosticSource.AfterActionResult(actionContext, result); + _diagnosticListener.AfterActionResult(actionContext, result); _logger.AfterExecutingActionResult(result); } } @@ -196,7 +195,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IAsyncAuthorizationFilter)state; var authorizationContext = _authorizationContext; - _diagnosticSource.BeforeOnAuthorizationAsync(authorizationContext, filter); + _diagnosticListener.BeforeOnAuthorizationAsync(authorizationContext, filter); _logger.BeforeExecutingMethodOnFilter( FilterTypeConstants.AuthorizationFilter, nameof(IAsyncAuthorizationFilter.OnAuthorizationAsync), @@ -220,7 +219,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IAsyncAuthorizationFilter)state; var authorizationContext = _authorizationContext; - _diagnosticSource.AfterOnAuthorizationAsync(authorizationContext, filter); + _diagnosticListener.AfterOnAuthorizationAsync(authorizationContext, filter); _logger.AfterExecutingMethodOnFilter( FilterTypeConstants.AuthorizationFilter, nameof(IAsyncAuthorizationFilter.OnAuthorizationAsync), @@ -242,7 +241,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IAuthorizationFilter)state; var authorizationContext = _authorizationContext; - _diagnosticSource.BeforeOnAuthorization(authorizationContext, filter); + _diagnosticListener.BeforeOnAuthorization(authorizationContext, filter); _logger.BeforeExecutingMethodOnFilter( FilterTypeConstants.AuthorizationFilter, nameof(IAuthorizationFilter.OnAuthorization), @@ -250,7 +249,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnAuthorization(authorizationContext); - _diagnosticSource.AfterOnAuthorization(authorizationContext, filter); + _diagnosticListener.AfterOnAuthorization(authorizationContext, filter); _logger.AfterExecutingMethodOnFilter( FilterTypeConstants.AuthorizationFilter, nameof(IAuthorizationFilter.OnAuthorization), @@ -333,7 +332,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IAsyncResourceFilter)state; var resourceExecutingContext = _resourceExecutingContext; - _diagnosticSource.BeforeOnResourceExecution(resourceExecutingContext, filter); + _diagnosticListener.BeforeOnResourceExecution(resourceExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( FilterTypeConstants.ResourceFilter, nameof(IAsyncResourceFilter.OnResourceExecutionAsync), @@ -364,7 +363,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal Result = _resourceExecutingContext.Result, }; - _diagnosticSource.AfterOnResourceExecution(_resourceExecutedContext, filter); + _diagnosticListener.AfterOnResourceExecution(_resourceExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( FilterTypeConstants.ResourceFilter, nameof(IAsyncResourceFilter.OnResourceExecutionAsync), @@ -388,7 +387,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IResourceFilter)state; var resourceExecutingContext = _resourceExecutingContext; - _diagnosticSource.BeforeOnResourceExecuting(resourceExecutingContext, filter); + _diagnosticListener.BeforeOnResourceExecuting(resourceExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( FilterTypeConstants.ResourceFilter, nameof(IResourceFilter.OnResourceExecuting), @@ -396,7 +395,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnResourceExecuting(resourceExecutingContext); - _diagnosticSource.AfterOnResourceExecuting(resourceExecutingContext, filter); + _diagnosticListener.AfterOnResourceExecuting(resourceExecutingContext, filter); _logger.AfterExecutingMethodOnFilter( FilterTypeConstants.ResourceFilter, nameof(IResourceFilter.OnResourceExecuting), @@ -432,7 +431,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IResourceFilter)state; var resourceExecutedContext = _resourceExecutedContext; - _diagnosticSource.BeforeOnResourceExecuted(resourceExecutedContext, filter); + _diagnosticListener.BeforeOnResourceExecuted(resourceExecutedContext, filter); _logger.BeforeExecutingMethodOnFilter( FilterTypeConstants.ResourceFilter, nameof(IResourceFilter.OnResourceExecuted), @@ -440,7 +439,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnResourceExecuted(resourceExecutedContext); - _diagnosticSource.AfterOnResourceExecuted(resourceExecutedContext, filter); + _diagnosticListener.AfterOnResourceExecuted(resourceExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( FilterTypeConstants.ResourceFilter, nameof(IResourceFilter.OnResourceExecuted), @@ -528,7 +527,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal // we'll call the filter. Otherwise there's nothing to do. if (exceptionContext?.Exception != null && !exceptionContext.ExceptionHandled) { - _diagnosticSource.BeforeOnExceptionAsync(exceptionContext, filter); + _diagnosticListener.BeforeOnExceptionAsync(exceptionContext, filter); _logger.BeforeExecutingMethodOnFilter( FilterTypeConstants.ExceptionFilter, nameof(IAsyncExceptionFilter.OnExceptionAsync), @@ -555,7 +554,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (IAsyncExceptionFilter)state; var exceptionContext = _exceptionContext; - _diagnosticSource.AfterOnExceptionAsync(exceptionContext, filter); + _diagnosticListener.AfterOnExceptionAsync(exceptionContext, filter); _logger.AfterExecutingMethodOnFilter( FilterTypeConstants.ExceptionFilter, nameof(IAsyncExceptionFilter.OnExceptionAsync), @@ -595,7 +594,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal // we'll call the filter. Otherwise there's nothing to do. if (exceptionContext?.Exception != null && !exceptionContext.ExceptionHandled) { - _diagnosticSource.BeforeOnException(exceptionContext, filter); + _diagnosticListener.BeforeOnException(exceptionContext, filter); _logger.BeforeExecutingMethodOnFilter( FilterTypeConstants.ExceptionFilter, nameof(IExceptionFilter.OnException), @@ -603,7 +602,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnException(exceptionContext); - _diagnosticSource.AfterOnException(exceptionContext, filter); + _diagnosticListener.AfterOnException(exceptionContext, filter); _logger.AfterExecutingMethodOnFilter( FilterTypeConstants.ExceptionFilter, nameof(IExceptionFilter.OnException), @@ -632,7 +631,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal // either by setting ExceptionHandled, or nulling out the Exception or setting a result // on the ExceptionContext. // - // We need to execute the result (if any) and then exit gracefully which unwinding Resource + // We need to execute the result (if any) and then exit gracefully which unwinding Resource // filters. Debug.Assert(state != null); @@ -905,7 +904,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (TFilterAsync)state; var resultExecutingContext = _resultExecutingContext; - _diagnosticSource.BeforeOnResultExecution(resultExecutingContext, filter); + _diagnosticListener.BeforeOnResultExecution(resultExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( resultFilterKind, nameof(IAsyncResultFilter.OnResultExecutionAsync), @@ -945,7 +944,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal }; } - _diagnosticSource.AfterOnResultExecution(_resultExecutedContext, filter); + _diagnosticListener.AfterOnResultExecution(_resultExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( resultFilterKind, nameof(IAsyncResultFilter.OnResultExecutionAsync), @@ -962,7 +961,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (TFilter)state; var resultExecutingContext = _resultExecutingContext; - _diagnosticSource.BeforeOnResultExecuting(resultExecutingContext, filter); + _diagnosticListener.BeforeOnResultExecuting(resultExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( resultFilterKind, nameof(IResultFilter.OnResultExecuting), @@ -970,7 +969,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnResultExecuting(resultExecutingContext); - _diagnosticSource.AfterOnResultExecuting(resultExecutingContext, filter); + _diagnosticListener.AfterOnResultExecuting(resultExecutingContext, filter); _logger.AfterExecutingMethodOnFilter( resultFilterKind, nameof(IResultFilter.OnResultExecuting), @@ -1012,7 +1011,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal var filter = (TFilter)state; var resultExecutedContext = _resultExecutedContext; - _diagnosticSource.BeforeOnResultExecuted(resultExecutedContext, filter); + _diagnosticListener.BeforeOnResultExecuted(resultExecutedContext, filter); _logger.BeforeExecutingMethodOnFilter( resultFilterKind, nameof(IResultFilter.OnResultExecuted), @@ -1020,7 +1019,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal filter.OnResultExecuted(resultExecutedContext); - _diagnosticSource.AfterOnResultExecuted(resultExecutedContext, filter); + _diagnosticListener.AfterOnResultExecuted(resultExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( resultFilterKind, nameof(IResultFilter.OnResultExecuted), diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/TypeActivatorCache.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/TypeActivatorCache.cs similarity index 86% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/TypeActivatorCache.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/TypeActivatorCache.cs index 36c0d947d3..f94f491a81 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/TypeActivatorCache.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/TypeActivatorCache.cs @@ -5,13 +5,13 @@ using System; using System.Collections.Concurrent; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Infrastructure { /// - /// Caches instances produced by - /// . + /// Caches instances produced by + /// . /// - public class TypeActivatorCache : ITypeActivatorCache + internal class TypeActivatorCache : ITypeActivatorCache { private readonly Func _createFactory = (type) => ActivatorUtilities.CreateFactory(type, Type.EmptyTypes); @@ -37,4 +37,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal return (TInstance)createFactory(serviceProvider, arguments: null); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/VirtualFileResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/VirtualFileResultExecutor.cs index d9702a572f..97a0584b9f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/VirtualFileResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/VirtualFileResultExecutor.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionAttributeRouteModel.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionAttributeRouteModel.cs deleted file mode 100644 index 45fe4b2578..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionAttributeRouteModel.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Mvc.ApplicationModels; - -namespace Microsoft.AspNetCore.Mvc.Internal -{ - public static class ActionAttributeRouteModel - { - public static IEnumerable<(AttributeRouteModel route, SelectorModel actionSelector, SelectorModel controllerSelector)> GetAttributeRoutes(ActionModel actionModel) - { - var controllerAttributeRoutes = actionModel.Controller.Selectors - .Where(sm => sm.AttributeRouteModel != null) - .Select(sm => sm.AttributeRouteModel) - .ToList(); - - foreach (var actionSelectorModel in actionModel.Selectors) - { - var actionRouteModel = actionSelectorModel.AttributeRouteModel; - - // We check the action to see if the template allows combination behavior - // (It doesn't start with / or ~/) so that in the case where we have multiple - // [Route] attributes on the controller we don't end up creating multiple - if (actionRouteModel != null && actionRouteModel.IsAbsoluteTemplate) - { - var route = AttributeRouteModel.CombineAttributeRouteModel( - left: null, - right: actionRouteModel); - - yield return (route, actionSelectorModel, null); - } - else if (controllerAttributeRoutes.Count > 0) - { - for (var i = 0; i < actionModel.Controller.Selectors.Count; i++) - { - // We're using the attribute routes from the controller - var controllerSelector = actionModel.Controller.Selectors[i]; - - var route = AttributeRouteModel.CombineAttributeRouteModel( - controllerSelector.AttributeRouteModel, - actionRouteModel); - - yield return (route, actionSelectorModel, controllerSelector); - } - } - - else - { - var route = AttributeRouteModel.CombineAttributeRouteModel( - left: null, - right: actionRouteModel); - - yield return (route, actionSelectorModel, null); - } - } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs deleted file mode 100644 index 21ec3aee6b..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs +++ /dev/null @@ -1,637 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using Microsoft.AspNetCore.Mvc.Abstractions; -using Microsoft.AspNetCore.Mvc.ActionConstraints; -using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.Controllers; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Routing; -using Microsoft.AspNetCore.Routing; -using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; - -namespace Microsoft.AspNetCore.Mvc.Internal -{ - /// - /// Creates instances of from . - /// - public static class ControllerActionDescriptorBuilder - { - // This is the default order for attribute routes whose order calculated from - // the controller model is null. - private const int DefaultAttributeRouteOrder = 0; - - /// - /// Creates instances of from . - /// - /// The . - /// The list of . - public static IList Build(ApplicationModel application) - { - var actions = new List(); - - var methodInfoMap = new MethodToActionMap(); - - var routeTemplateErrors = new List(); - var attributeRoutingConfigurationErrors = new Dictionary(); - - foreach (var controller in application.Controllers) - { - // Only add properties which are explicitly marked to bind. - // The attribute check is required for ModelBinder attribute. - var controllerPropertyDescriptors = controller.ControllerProperties - .Where(p => p.BindingInfo != null) - .Select(CreateParameterDescriptor) - .ToList(); - foreach (var action in controller.Actions) - { - // Controllers with multiple [Route] attributes (or user defined implementation of - // IRouteTemplateProvider) will generate one action descriptor per IRouteTemplateProvider - // instance. - // Actions with multiple [Http*] attributes or other (IRouteTemplateProvider implementations - // have already been identified as different actions during action discovery. - var actionDescriptors = CreateActionDescriptors(application, controller, action); - - foreach (var actionDescriptor in actionDescriptors) - { - actionDescriptor.ControllerName = controller.ControllerName; - actionDescriptor.ControllerTypeInfo = controller.ControllerType; - - AddApiExplorerInfo(actionDescriptor, application, controller, action); - AddRouteValues(actionDescriptor, controller, action); - AddProperties(actionDescriptor, action, controller, application); - - actionDescriptor.BoundProperties = controllerPropertyDescriptors; - - if (IsAttributeRoutedAction(actionDescriptor)) - { - // Replaces tokens like [controller]/[action] in the route template with the actual values - // for this action. - ReplaceAttributeRouteTokens(actionDescriptor, routeTemplateErrors); - } - } - - methodInfoMap.AddToMethodInfo(action, actionDescriptors); - actions.AddRange(actionDescriptors); - } - } - - var actionsByRouteName = new Dictionary>( - StringComparer.OrdinalIgnoreCase); - - // Keeps track of all the methods that we've validated to avoid visiting each action group - // more than once. - var validatedMethods = new HashSet(); - - foreach (var actionDescriptor in actions) - { - if (!validatedMethods.Contains(actionDescriptor.MethodInfo)) - { - ValidateActionGroupConfiguration( - methodInfoMap, - actionDescriptor, - attributeRoutingConfigurationErrors); - - validatedMethods.Add(actionDescriptor.MethodInfo); - } - - var attributeRouteInfo = actionDescriptor.AttributeRouteInfo; - if (attributeRouteInfo?.Name != null) - { - // Build a map of attribute route name to action descriptors to ensure that all - // attribute routes with a given name have the same template. - AddActionToNamedGroup(actionsByRouteName, attributeRouteInfo.Name, actionDescriptor); - } - } - - if (attributeRoutingConfigurationErrors.Any()) - { - var message = CreateAttributeRoutingAggregateErrorMessage( - attributeRoutingConfigurationErrors.Values); - - throw new InvalidOperationException(message); - } - - var namedRoutedErrors = ValidateNamedAttributeRoutedActions(actionsByRouteName); - if (namedRoutedErrors.Any()) - { - var message = CreateAttributeRoutingAggregateErrorMessage(namedRoutedErrors); - throw new InvalidOperationException(message); - } - - if (routeTemplateErrors.Any()) - { - var message = CreateAttributeRoutingAggregateErrorMessage(routeTemplateErrors); - throw new InvalidOperationException(message); - } - - return actions; - } - - private static IList CreateActionDescriptors( - ApplicationModel application, - ControllerModel controller, - ActionModel action) - { - var defaultControllerConstraints = Enumerable.Empty(); - var defaultControllerEndpointMetadata = Enumerable.Empty(); - if (controller.Selectors.Count > 0) - { - defaultControllerConstraints = controller.Selectors[0].ActionConstraints - .Where(constraint => !(constraint is IRouteTemplateProvider)); - defaultControllerEndpointMetadata = controller.Selectors[0].EndpointMetadata; - } - - var actionDescriptors = new List(); - foreach (var result in ActionAttributeRouteModel.GetAttributeRoutes(action)) - { - var actionSelector = result.actionSelector; - var controllerSelector = result.controllerSelector; - - var actionDescriptor = CreateActionDescriptor(action, result.route); - actionDescriptors.Add(actionDescriptor); - AddActionFilters(actionDescriptor, action.Filters, controller.Filters, application.Filters); - - var controllerConstraints = defaultControllerConstraints; - - if (controllerSelector?.AttributeRouteModel?.Attribute is IActionConstraintMetadata actionConstraint) - { - // Use the attribute route as a constraint if the controller selector participated in creating this route. - controllerConstraints = controllerConstraints.Concat(new[] { actionConstraint }); - } - - AddActionConstraints(actionDescriptor, actionSelector, controllerConstraints); - - // Metadata for the action is more significant so order it before the controller metadata - var actionDescriptorMetadata = actionSelector.EndpointMetadata.ToList(); - actionDescriptorMetadata.AddRange(defaultControllerEndpointMetadata); - - actionDescriptor.EndpointMetadata = actionDescriptorMetadata; - } - - return actionDescriptors; - } - - private static ControllerActionDescriptor CreateActionDescriptor(ActionModel action, AttributeRouteModel routeModel) - { - var parameterDescriptors = new List(); - foreach (var parameter in action.Parameters) - { - var parameterDescriptor = CreateParameterDescriptor(parameter); - parameterDescriptors.Add(parameterDescriptor); - } - - var actionDescriptor = new ControllerActionDescriptor - { - ActionName = action.ActionName, - MethodInfo = action.ActionMethod, - Parameters = parameterDescriptors, - AttributeRouteInfo = CreateAttributeRouteInfo(routeModel), - }; - - return actionDescriptor; - } - - private static ParameterDescriptor CreateParameterDescriptor(ParameterModel parameterModel) - { - var parameterDescriptor = new ControllerParameterDescriptor() - { - Name = parameterModel.ParameterName, - ParameterType = parameterModel.ParameterInfo.ParameterType, - BindingInfo = parameterModel.BindingInfo, - ParameterInfo = parameterModel.ParameterInfo, - }; - - return parameterDescriptor; - } - - private static ParameterDescriptor CreateParameterDescriptor(PropertyModel propertyModel) - { - var parameterDescriptor = new ControllerBoundPropertyDescriptor() - { - BindingInfo = propertyModel.BindingInfo, - Name = propertyModel.PropertyName, - ParameterType = propertyModel.PropertyInfo.PropertyType, - PropertyInfo = propertyModel.PropertyInfo, - }; - - return parameterDescriptor; - } - - private static void AddApiExplorerInfo( - ControllerActionDescriptor actionDescriptor, - ApplicationModel application, - ControllerModel controller, - ActionModel action) - { - var isVisible = - action.ApiExplorer?.IsVisible ?? - controller.ApiExplorer?.IsVisible ?? - application.ApiExplorer?.IsVisible ?? - false; - - var isVisibleSetOnActionOrController = - action.ApiExplorer?.IsVisible ?? - controller.ApiExplorer?.IsVisible ?? - false; - - // ApiExplorer isn't supported on conventional-routed actions, but we still allow you to configure - // it at the application level when you have a mix of controller types. We'll just skip over enabling - // ApiExplorer for conventional-routed controllers when this happens. - var isVisibleSetOnApplication = application.ApiExplorer?.IsVisible ?? false; - - if (isVisibleSetOnActionOrController && !IsAttributeRoutedAction(actionDescriptor)) - { - // ApiExplorer is only supported on attribute routed actions. - throw new InvalidOperationException(Resources.FormatApiExplorer_UnsupportedAction( - actionDescriptor.DisplayName)); - } - else if (isVisibleSetOnApplication && !IsAttributeRoutedAction(actionDescriptor)) - { - // This is the case where we're going to be lenient, just ignore it. - } - else if (isVisible) - { - Debug.Assert(IsAttributeRoutedAction(actionDescriptor)); - - var apiExplorerActionData = new ApiDescriptionActionData() - { - GroupName = action.ApiExplorer?.GroupName ?? controller.ApiExplorer?.GroupName, - }; - - actionDescriptor.SetProperty(apiExplorerActionData); - } - } - - private static void AddProperties( - ControllerActionDescriptor actionDescriptor, - ActionModel action, - ControllerModel controller, - ApplicationModel application) - { - foreach (var item in application.Properties) - { - actionDescriptor.Properties[item.Key] = item.Value; - } - - foreach (var item in controller.Properties) - { - actionDescriptor.Properties[item.Key] = item.Value; - } - - foreach (var item in action.Properties) - { - actionDescriptor.Properties[item.Key] = item.Value; - } - } - - private static void AddActionFilters( - ControllerActionDescriptor actionDescriptor, - IEnumerable actionFilters, - IEnumerable controllerFilters, - IEnumerable globalFilters) - { - actionDescriptor.FilterDescriptors = - actionFilters.Select(f => new FilterDescriptor(f, FilterScope.Action)) - .Concat(controllerFilters.Select(f => new FilterDescriptor(f, FilterScope.Controller))) - .Concat(globalFilters.Select(f => new FilterDescriptor(f, FilterScope.Global))) - .OrderBy(d => d, FilterDescriptorOrderComparer.Comparer) - .ToList(); - } - - private static AttributeRouteInfo CreateAttributeRouteInfo(AttributeRouteModel routeModel) - { - if (routeModel == null) - { - return null; - } - - return new AttributeRouteInfo - { - Template = routeModel.Template, - Order = routeModel.Order ?? DefaultAttributeRouteOrder, - Name = routeModel.Name, - SuppressLinkGeneration = routeModel.SuppressLinkGeneration, - SuppressPathMatching = routeModel.SuppressPathMatching, - }; - } - - private static void AddActionConstraints( - ControllerActionDescriptor actionDescriptor, - SelectorModel selectorModel, - IEnumerable controllerConstraints) - { - var constraints = new List(); - - if (selectorModel.ActionConstraints != null) - { - constraints.AddRange(selectorModel.ActionConstraints); - } - - if (controllerConstraints != null) - { - constraints.AddRange(controllerConstraints); - } - - if (constraints.Count > 0) - { - actionDescriptor.ActionConstraints = constraints; - } - } - - public static void AddRouteValues( - ControllerActionDescriptor actionDescriptor, - ControllerModel controller, - ActionModel action) - { - // Apply all the constraints defined on the action, then controller (for example, [Area]) - // to the actions. Also keep track of all the constraints that require preventing actions - // without the constraint to match. For example, actions without an [Area] attribute on their - // controller should not match when a value has been given for area when matching a url or - // generating a link. - foreach (var kvp in action.RouteValues) - { - // Skip duplicates - if (!actionDescriptor.RouteValues.ContainsKey(kvp.Key)) - { - actionDescriptor.RouteValues.Add(kvp.Key, kvp.Value); - } - } - - foreach (var kvp in controller.RouteValues) - { - // Skip duplicates - this also means that a value on the action will take precedence - if (!actionDescriptor.RouteValues.ContainsKey(kvp.Key)) - { - actionDescriptor.RouteValues.Add(kvp.Key, kvp.Value); - } - } - - // Lastly add the 'default' values - if (!actionDescriptor.RouteValues.ContainsKey("action")) - { - actionDescriptor.RouteValues.Add("action", action.ActionName ?? string.Empty); - } - - if (!actionDescriptor.RouteValues.ContainsKey("controller")) - { - actionDescriptor.RouteValues.Add("controller", controller.ControllerName); - } - } - - private static void ReplaceAttributeRouteTokens( - ControllerActionDescriptor actionDescriptor, - IList routeTemplateErrors) - { - try - { - actionDescriptor.Properties.TryGetValue(typeof(IOutboundParameterTransformer), out var transformer); - var routeTokenTransformer = transformer as IOutboundParameterTransformer; - - actionDescriptor.AttributeRouteInfo.Template = AttributeRouteModel.ReplaceTokens( - actionDescriptor.AttributeRouteInfo.Template, - actionDescriptor.RouteValues, - routeTokenTransformer); - - if (actionDescriptor.AttributeRouteInfo.Name != null) - { - actionDescriptor.AttributeRouteInfo.Name = AttributeRouteModel.ReplaceTokens( - actionDescriptor.AttributeRouteInfo.Name, - actionDescriptor.RouteValues, - routeTokenTransformer); - } - } - catch (InvalidOperationException ex) - { - // Routing will throw an InvalidOperationException here if we can't parse/replace tokens - // in the template. - var message = Resources.FormatAttributeRoute_IndividualErrorMessage( - actionDescriptor.DisplayName, - Environment.NewLine, - ex.Message); - - routeTemplateErrors.Add(message); - } - } - - private static void AddActionToNamedGroup( - IDictionary> actionsByRouteName, - string routeName, - ControllerActionDescriptor actionDescriptor) - { - if (actionsByRouteName.TryGetValue(routeName, out var namedActionGroup)) - { - namedActionGroup.Add(actionDescriptor); - } - else - { - namedActionGroup = new List(); - namedActionGroup.Add(actionDescriptor); - actionsByRouteName.Add(routeName, namedActionGroup); - } - } - - private static bool IsAttributeRoutedAction(ControllerActionDescriptor actionDescriptor) - { - return actionDescriptor.AttributeRouteInfo?.Template != null; - } - - private static IList AddErrorNumbers( - IEnumerable namedRoutedErrors) - { - return namedRoutedErrors - .Select((error, i) => - Resources.FormatAttributeRoute_AggregateErrorMessage_ErrorNumber( - i + 1, - Environment.NewLine, - error)) - .ToList(); - } - - private static IList ValidateNamedAttributeRoutedActions( - IDictionary> actionsGroupedByRouteName) - { - var namedRouteErrors = new List(); - - foreach (var kvp in actionsGroupedByRouteName) - { - // We are looking for attribute routed actions that have the same name but - // different route templates. We pick the first template of the group and - // we compare it against the rest of the templates that have that same name - // associated. - // The moment we find one that is different we report the whole group to the - // user in the error message so that he can see the different actions and the - // different templates for a given named attribute route. - var firstActionDescriptor = kvp.Value[0]; - var firstTemplate = firstActionDescriptor.AttributeRouteInfo.Template; - - for (var i = 1; i < kvp.Value.Count; i++) - { - var otherActionDescriptor = kvp.Value[i]; - var otherActionTemplate = otherActionDescriptor.AttributeRouteInfo.Template; - - if (!firstTemplate.Equals(otherActionTemplate, StringComparison.OrdinalIgnoreCase)) - { - var descriptions = kvp.Value.Select(ad => - Resources.FormatAttributeRoute_DuplicateNames_Item( - ad.DisplayName, - ad.AttributeRouteInfo.Template)); - - var errorDescription = string.Join(Environment.NewLine, descriptions); - var message = Resources.FormatAttributeRoute_DuplicateNames( - kvp.Key, - Environment.NewLine, - errorDescription); - - namedRouteErrors.Add(message); - break; - } - } - } - - return namedRouteErrors; - } - - private static void ValidateActionGroupConfiguration( - IDictionary>> methodMap, - ControllerActionDescriptor actionDescriptor, - IDictionary routingConfigurationErrors) - { - var hasAttributeRoutedActions = false; - var hasConventionallyRoutedActions = false; - - var actionsForMethod = methodMap[actionDescriptor.MethodInfo]; - foreach (var reflectedAction in actionsForMethod) - { - foreach (var action in reflectedAction.Value) - { - if (IsAttributeRoutedAction(action)) - { - hasAttributeRoutedActions = true; - } - else - { - hasConventionallyRoutedActions = true; - } - } - } - - // Validate that no method result in attribute and non attribute actions at the same time. - // By design, mixing attribute and conventionally actions in the same method is not allowed. - // - // This for example: - // - // [HttpGet] - // [HttpPost("Foo")] - // public void Foo() { } - if (hasAttributeRoutedActions && hasConventionallyRoutedActions) - { - var message = CreateMixedRoutedActionDescriptorsErrorMessage( - actionDescriptor, - actionsForMethod); - - routingConfigurationErrors.Add(actionDescriptor.MethodInfo, message); - } - } - - private static string CreateMixedRoutedActionDescriptorsErrorMessage( - ControllerActionDescriptor actionDescriptor, - IDictionary> actionsForMethod) - { - // Text to show as the attribute route template for conventionally routed actions. - var nullTemplate = Resources.AttributeRoute_NullTemplateRepresentation; - - var actionDescriptions = new List(); - foreach (var action in actionsForMethod.SelectMany(kvp => kvp.Value)) - { - var routeTemplate = action.AttributeRouteInfo?.Template ?? nullTemplate; - - var verbs = action.ActionConstraints?.OfType() - .FirstOrDefault()?.HttpMethods; - - var formattedVerbs = string.Empty; - if (verbs != null) - { - formattedVerbs = string.Join(", ", verbs.OrderBy(v => v, StringComparer.OrdinalIgnoreCase)); - } - - var description = - Resources.FormatAttributeRoute_MixedAttributeAndConventionallyRoutedActions_ForMethod_Item( - action.DisplayName, - routeTemplate, - formattedVerbs); - - actionDescriptions.Add(description); - } - - // Sample error message: - // - // A method 'MyApplication.CustomerController.Index' must not define attributed actions and - // non attributed actions at the same time: - // Action: 'MyApplication.CustomerController.Index' - Route Template: 'Products' - HTTP Verbs: 'PUT' - // Action: 'MyApplication.CustomerController.Index' - Route Template: '(none)' - HTTP Verbs: 'POST' - // - // Use 'AcceptVerbsAttribute' to create a single route that allows multiple HTTP verbs and defines a route, - // or set a route template in all attributes that constrain HTTP verbs. - return - Resources.FormatAttributeRoute_MixedAttributeAndConventionallyRoutedActions_ForMethod( - actionDescriptor.DisplayName, - Environment.NewLine, - string.Join(Environment.NewLine, actionDescriptions)); - } - - private static string CreateAttributeRoutingAggregateErrorMessage( - IEnumerable individualErrors) - { - var errorMessages = AddErrorNumbers(individualErrors); - - var message = Resources.FormatAttributeRoute_AggregateErrorMessage( - Environment.NewLine, - string.Join(Environment.NewLine + Environment.NewLine, errorMessages)); - return message; - } - - // We need to build a map of methods to reflected actions and reflected actions to - // action descriptors so that we can validate later that no method produced attribute - // and non attributed actions at the same time, and that no method that produced attribute - // routed actions has no attributes that implement IActionHttpMethodProvider and do not - // implement IRouteTemplateProvider. For example: - // - // public class ProductsController - // { - // [HttpGet("Products")] - // [HttpPost] - // public ActionResult Items(){ ... } - // - // [HttpGet("Products")] - // [CustomHttpMethods("POST, PUT")] - // public ActionResult List(){ ... } - // } - private class MethodToActionMap : - Dictionary>> - { - public void AddToMethodInfo( - ActionModel action, - IList actionDescriptors) - { - if (TryGetValue(action.ActionMethod, out var actionsForMethod)) - { - actionsForMethod.Add(action, actionDescriptors); - } - else - { - var reflectedActionMap = - new Dictionary>(); - reflectedActionMap.Add(action, actionDescriptors); - Add(action.ActionMethod, reflectedActionMap); - } - } - } - } -} \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreDiagnosticSourceExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreDiagnosticSourceExtensions.cs deleted file mode 100644 index d5bee24ba7..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreDiagnosticSourceExtensions.cs +++ /dev/null @@ -1,712 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Abstractions; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Routing; - -namespace Microsoft.AspNetCore.Mvc.Internal -{ - // We're doing a lot of asserts here because these methods are really tedious to test and - // highly dependent on the details of the invoker's state machine. Basically if we wrote the - // obvious unit tests that would generate a lot of boilerplate and wouldn't cover the hard parts. - public static class MvcCoreDiagnosticSourceExtensions - { - public static void BeforeAction( - this DiagnosticSource diagnosticSource, - ActionDescriptor actionDescriptor, - HttpContext httpContext, - RouteData routeData) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionDescriptor != null); - Debug.Assert(httpContext != null); - Debug.Assert(routeData != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeAction")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeAction", - new { actionDescriptor, httpContext = httpContext, routeData = routeData }); - } - } - - public static void AfterAction( - this DiagnosticSource diagnosticSource, - ActionDescriptor actionDescriptor, - HttpContext httpContext, - RouteData routeData) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionDescriptor != null); - Debug.Assert(httpContext != null); - Debug.Assert(routeData != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterAction")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterAction", - new { actionDescriptor, httpContext = httpContext, routeData = routeData }); - } - } - - public static void BeforeOnAuthorizationAsync( - this DiagnosticSource diagnosticSource, - AuthorizationFilterContext authorizationContext, - IAsyncAuthorizationFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(authorizationContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", - new - { - actionDescriptor = authorizationContext.ActionDescriptor, - authorizationContext = authorizationContext, - filter = filter - }); - } - } - - public static void AfterOnAuthorizationAsync( - this DiagnosticSource diagnosticSource, - AuthorizationFilterContext authorizationContext, - IAsyncAuthorizationFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(authorizationContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnAuthorization", - new - { - actionDescriptor = authorizationContext.ActionDescriptor, - authorizationContext = authorizationContext, - filter = filter - }); - } - } - - public static void BeforeOnAuthorization( - this DiagnosticSource diagnosticSource, - AuthorizationFilterContext authorizationContext, - IAuthorizationFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(authorizationContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", - new - { - actionDescriptor = authorizationContext.ActionDescriptor, - authorizationContext = authorizationContext, - filter = filter - }); - } - } - - public static void AfterOnAuthorization( - this DiagnosticSource diagnosticSource, - AuthorizationFilterContext authorizationContext, - IAuthorizationFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(authorizationContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnAuthorization", - new - { - actionDescriptor = authorizationContext.ActionDescriptor, - authorizationContext = authorizationContext, - filter = filter - }); - } - } - - public static void BeforeOnResourceExecution( - this DiagnosticSource diagnosticSource, - ResourceExecutingContext resourceExecutingContext, - IAsyncResourceFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resourceExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution", - new - { - actionDescriptor = resourceExecutingContext.ActionDescriptor, - resourceExecutingContext = resourceExecutingContext, - filter = filter - }); - } - } - - public static void AfterOnResourceExecution( - this DiagnosticSource diagnosticSource, - ResourceExecutedContext resourceExecutedContext, - IAsyncResourceFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resourceExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnResourceExecution", - new - { - actionDescriptor = resourceExecutedContext.ActionDescriptor, - resourceExecutedContext = resourceExecutedContext, - filter = filter - }); - } - } - - public static void BeforeOnResourceExecuting( - this DiagnosticSource diagnosticSource, - ResourceExecutingContext resourceExecutingContext, - IResourceFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resourceExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting", - new - { - actionDescriptor = resourceExecutingContext.ActionDescriptor, - resourceExecutingContext = resourceExecutingContext, - filter = filter - }); - } - } - - public static void AfterOnResourceExecuting( - this DiagnosticSource diagnosticSource, - ResourceExecutingContext resourceExecutingContext, - IResourceFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resourceExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting", - new - { - actionDescriptor = resourceExecutingContext.ActionDescriptor, - resourceExecutingContext = resourceExecutingContext, - filter = filter - }); - } - } - - public static void BeforeOnResourceExecuted( - this DiagnosticSource diagnosticSource, - ResourceExecutedContext resourceExecutedContext, - IResourceFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resourceExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted", - new - { - actionDescriptor = resourceExecutedContext.ActionDescriptor, - resourceExecutedContext = resourceExecutedContext, - filter = filter - }); - } - } - - public static void AfterOnResourceExecuted( - this DiagnosticSource diagnosticSource, - ResourceExecutedContext resourceExecutedContext, - IResourceFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resourceExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted", - new - { - actionDescriptor = resourceExecutedContext.ActionDescriptor, - resourceExecutedContext = resourceExecutedContext, - filter = filter - }); - } - } - - public static void BeforeOnExceptionAsync( - this DiagnosticSource diagnosticSource, - ExceptionContext exceptionContext, - IAsyncExceptionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(exceptionContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnException", - new - { - actionDescriptor = exceptionContext.ActionDescriptor, - exceptionContext = exceptionContext, - filter = filter - }); - } - } - - public static void AfterOnExceptionAsync( - this DiagnosticSource diagnosticSource, - ExceptionContext exceptionContext, - IAsyncExceptionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(exceptionContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnException", - new - { - actionDescriptor = exceptionContext.ActionDescriptor, - exceptionContext = exceptionContext, - filter = filter - }); - } - } - - public static void BeforeOnException( - this DiagnosticSource diagnosticSource, - ExceptionContext exceptionContext, - IExceptionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(exceptionContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnException", - new - { - actionDescriptor = exceptionContext.ActionDescriptor, - exceptionContext = exceptionContext, - filter = filter - }); - } - } - - public static void AfterOnException( - this DiagnosticSource diagnosticSource, - ExceptionContext exceptionContext, - IExceptionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(exceptionContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnException", - new - { - actionDescriptor = exceptionContext.ActionDescriptor, - exceptionContext = exceptionContext, - filter = filter - }); - } - } - - public static void BeforeOnActionExecution( - this DiagnosticSource diagnosticSource, - ActionExecutingContext actionExecutingContext, - IAsyncActionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnActionExecution", - new - { - actionDescriptor = actionExecutingContext.ActionDescriptor, - actionExecutingContext = actionExecutingContext, - filter = filter - }); - } - } - - public static void AfterOnActionExecution( - this DiagnosticSource diagnosticSource, - ActionExecutedContext actionExecutedContext, - IAsyncActionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnActionExecution", - new - { - actionDescriptor = actionExecutedContext.ActionDescriptor, - actionExecutedContext = actionExecutedContext, - filter = filter - }); - } - } - - public static void BeforeOnActionExecuting( - this DiagnosticSource diagnosticSource, - ActionExecutingContext actionExecutingContext, - IActionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting", - new - { - actionDescriptor = actionExecutingContext.ActionDescriptor, - actionExecutingContext = actionExecutingContext, - filter = filter - }); - } - } - - public static void AfterOnActionExecuting( - this DiagnosticSource diagnosticSource, - ActionExecutingContext actionExecutingContext, - IActionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnActionExecuting", - new - { - actionDescriptor = actionExecutingContext.ActionDescriptor, - actionExecutingContext = actionExecutingContext, - filter = filter - }); - } - } - - public static void BeforeOnActionExecuted( - this DiagnosticSource diagnosticSource, - ActionExecutedContext actionExecutedContext, - IActionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted", - new - { - actionDescriptor = actionExecutedContext.ActionDescriptor, - actionExecutedContext = actionExecutedContext, - filter = filter - }); - } - } - - public static void AfterOnActionExecuted( - this DiagnosticSource diagnosticSource, - ActionExecutedContext actionExecutedContext, - IActionFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnActionExecuted", - new - { - actionDescriptor = actionExecutedContext.ActionDescriptor, - actionExecutedContext = actionExecutedContext, - filter = filter - }); - } - } - - public static void BeforeActionMethod( - this DiagnosticSource diagnosticSource, - ActionContext actionContext, - IDictionary actionArguments, - object controller) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionContext != null); - Debug.Assert(actionArguments != null); - Debug.Assert(controller != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionMethod")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeActionMethod", - new - { - actionContext = actionContext, - arguments = actionArguments, - controller = controller - }); - } - } - - public static void AfterActionMethod( - this DiagnosticSource diagnosticSource, - ActionContext actionContext, - IDictionary actionArguments, - object controller, - IActionResult result) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionContext != null); - Debug.Assert(actionArguments != null); - Debug.Assert(controller != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionMethod")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterActionMethod", - new - { - actionContext = actionContext, - arguments = actionArguments, - controller = controller, - result = result - }); - } - } - - public static void BeforeOnResultExecution( - this DiagnosticSource diagnosticSource, - ResultExecutingContext resultExecutingContext, - IAsyncResultFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resultExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnResultExecution", - new - { - actionDescriptor = resultExecutingContext.ActionDescriptor, - resultExecutingContext = resultExecutingContext, - filter = filter - }); - } - } - - public static void AfterOnResultExecution( - this DiagnosticSource diagnosticSource, - ResultExecutedContext resultExecutedContext, - IAsyncResultFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resultExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnResultExecution", - new - { - actionDescriptor = resultExecutedContext.ActionDescriptor, - resultExecutedContext = resultExecutedContext, - filter = filter - }); - } - } - - public static void BeforeOnResultExecuting( - this DiagnosticSource diagnosticSource, - ResultExecutingContext resultExecutingContext, - IResultFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resultExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting", - new - { - actionDescriptor = resultExecutingContext.ActionDescriptor, - resultExecutingContext = resultExecutingContext, - filter = filter - }); - } - } - - public static void AfterOnResultExecuting( - this DiagnosticSource diagnosticSource, - ResultExecutingContext resultExecutingContext, - IResultFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resultExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnResultExecuting", - new - { - actionDescriptor = resultExecutingContext.ActionDescriptor, - resultExecutingContext = resultExecutingContext, - filter = filter - }); - } - } - - public static void BeforeOnResultExecuted( - this DiagnosticSource diagnosticSource, - ResultExecutedContext resultExecutedContext, - IResultFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resultExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted", - new - { - actionDescriptor = resultExecutedContext.ActionDescriptor, - resultExecutedContext = resultExecutedContext, - filter = filter - }); - } - } - - public static void AfterOnResultExecuted( - this DiagnosticSource diagnosticSource, - ResultExecutedContext resultExecutedContext, - IResultFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(resultExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnResultExecuted", - new - { - actionDescriptor = resultExecutedContext.ActionDescriptor, - resultExecutedContext = resultExecutedContext, - filter = filter - }); - } - } - - public static void BeforeActionResult( - this DiagnosticSource diagnosticSource, - ActionContext actionContext, - IActionResult result) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionContext != null); - Debug.Assert(result != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionResult")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeActionResult", - new { actionContext = actionContext, result = result }); - } - } - - public static void AfterActionResult( - this DiagnosticSource diagnosticSource, - ActionContext actionContext, - IActionResult result) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionContext != null); - Debug.Assert(result != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionResult")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterActionResult", - new { actionContext = actionContext, result = result }); - } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs index ca20eb5020..a600c39079 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/LocalRedirectResult.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Microsoft.AspNetCore.Mvc.Core.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Microsoft.AspNetCore.Mvc.Core.csproj index 7a21b34e45..d1e9953b50 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Microsoft.AspNetCore.Mvc.Core.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Microsoft.AspNetCore.Mvc.Core.csproj @@ -10,7 +10,7 @@ Microsoft.AspNetCore.Mvc.FromBodyAttribute Microsoft.AspNetCore.Mvc.FromFormAttribute Microsoft.AspNetCore.Mvc.RequireHttpsAttribute Microsoft.AspNetCore.Mvc.RouteAttribute - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs index 8e0744cfda..dd4051973c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/BodyModelBinder.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Binders diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs index 99461f9ec9..c3772d8383 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ByteArrayModelBinder.cs @@ -3,7 +3,6 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs index 372a7da770..881eb12992 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/CollectionModelBinder.cs @@ -9,8 +9,6 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs index 5c1e82a80c..2da15ed858 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/ComplexTypeModelBinder.cs @@ -7,7 +7,6 @@ using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs index 7692baa009..3670185732 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DecimalModelBinder.cs @@ -5,7 +5,6 @@ using System; using System.Globalization; using System.Runtime.ExceptionServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs index 0954f87e6c..d060a065f8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DictionaryModelBinder.cs @@ -6,8 +6,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs index 77d32d5a0d..3a62b2fa39 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/DoubleModelBinder.cs @@ -5,7 +5,6 @@ using System; using System.Globalization; using System.Runtime.ExceptionServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs index 515266d2df..c34a8be777 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FloatModelBinder.cs @@ -5,7 +5,6 @@ using System; using System.Globalization; using System.Runtime.ExceptionServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs index 41d96ed272..3c26cafb2d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormCollectionModelBinder.cs @@ -7,7 +7,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Primitives; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs index 76b4bf54ca..526225343e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs @@ -8,8 +8,6 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs index e9de376246..54ce71f896 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinder.cs @@ -6,8 +6,6 @@ using System.Diagnostics; using System.Globalization; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinderProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinderProvider.cs index c0f46ff93c..2b885e3617 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinderProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/HeaderModelBinderProvider.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs index ee90c3f01e..45aab720ba 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/KeyValuePairModelBinder.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs index 017049e769..de1f1da636 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/SimpleTypeModelBinder.cs @@ -5,7 +5,6 @@ using System; using System.ComponentModel; using System.Runtime.ExceptionServices; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultModelBindingContext.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultModelBindingContext.cs similarity index 100% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultModelBindingContext.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultModelBindingContext.cs diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs index 3d1bc81a71..6105b3adf0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/DefaultPropertyFilterProvider.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; namespace Microsoft.AspNetCore.Mvc.ModelBinding { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ElementalValueProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ElementalValueProvider.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ElementalValueProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ElementalValueProvider.cs index 83bfeed66a..7fefe4c9f8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ElementalValueProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ElementalValueProvider.cs @@ -3,11 +3,10 @@ using System; using System.Globalization; -using Microsoft.AspNetCore.Mvc.ModelBinding; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding { - public class ElementalValueProvider : IValueProvider + internal class ElementalValueProvider : IValueProvider { public ElementalValueProvider(string key, string value, CultureInfo culture) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs index 122d760af8..22df255b21 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/EmptyModelMetadataProvider.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs index da13af979e..278407db2d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/FormValueProvider.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Internal; namespace Microsoft.AspNetCore.Mvc.ModelBinding { @@ -14,7 +13,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public class FormValueProvider : BindingSourceValueProvider, IEnumerableValueProvider { - private readonly CultureInfo _culture; private readonly IFormCollection _values; private PrefixContainer _prefixContainer; @@ -41,14 +39,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding } _values = values; - _culture = culture; + Culture = culture; } - public CultureInfo Culture => _culture; + public CultureInfo Culture { get; } -#pragma warning disable PUB0001 // Pubternal type in public API protected PrefixContainer PrefixContainer -#pragma warning restore PUB0001 { get { @@ -86,6 +82,15 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding throw new ArgumentNullException(nameof(key)); } + if (key.Length == 0) + { + // Top level parameters will fall back to an empty prefix when the parameter name does not + // appear in any value provider. This would result in the parameter binding to a form parameter + // with a empty key (e.g. Request body looks like "=test") which isn't a scenario we want to support. + // Return a "None" result in this event. + return ValueProviderResult.None; + } + var values = _values[key]; if (values.Count == 0) { @@ -93,7 +98,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding } else { - return new ValueProviderResult(values, _culture); + return new ValueProviderResult(values, Culture); } } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryValueProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryValueProvider.cs index 6ae1c84377..581b18112c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryValueProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/JQueryValueProvider.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Mvc.ModelBinding @@ -52,9 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public CultureInfo Culture { get; } /// -#pragma warning disable PUB0001 // Pubternal type in public API protected PrefixContainer PrefixContainer -#pragma warning restore PUB0001 { get { @@ -82,8 +79,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public override ValueProviderResult GetValue(string key) { - StringValues values; - if (_values.TryGetValue(key, out values) && values.Count > 0) + if (key == null) + { + throw new ArgumentNullException(nameof(key)); + } + + if (_values.TryGetValue(key, out var values) && values.Count > 0) { return new ValueProviderResult(values, Culture); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultBindingMetadataProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultBindingMetadataProvider.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultBindingMetadataProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultBindingMetadataProvider.cs index 8e0546b992..5cc570394b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultBindingMetadataProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultBindingMetadataProvider.cs @@ -5,15 +5,13 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata { /// /// A default implementation of . /// - public class DefaultBindingMetadataProvider : IBindingMetadataProvider + internal class DefaultBindingMetadataProvider : IBindingMetadataProvider { public void CreateBindingMetadata(BindingMetadataProviderContext context) { @@ -128,4 +126,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCompositeMetadataDetailsProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultCompositeMetadataDetailsProvider.cs similarity index 80% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCompositeMetadataDetailsProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultCompositeMetadataDetailsProvider.cs index 37dfed3868..18792c320e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCompositeMetadataDetailsProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultCompositeMetadataDetailsProvider.cs @@ -4,14 +4,13 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata { /// /// A default implementation of . /// - public class DefaultCompositeMetadataDetailsProvider : ICompositeMetadataDetailsProvider + internal class DefaultCompositeMetadataDetailsProvider : ICompositeMetadataDetailsProvider { private readonly IEnumerable _providers; @@ -25,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } /// - public virtual void CreateBindingMetadata(BindingMetadataProviderContext context) + public void CreateBindingMetadata(BindingMetadataProviderContext context) { if (context == null) { @@ -39,7 +38,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } /// - public virtual void CreateDisplayMetadata(DisplayMetadataProviderContext context) + public void CreateDisplayMetadata(DisplayMetadataProviderContext context) { if (context == null) { @@ -53,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } /// - public virtual void CreateValidationMetadata(ValidationMetadataProviderContext context) + public void CreateValidationMetadata(ValidationMetadataProviderContext context) { if (context == null) { @@ -66,4 +65,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultValidationMetadataProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultValidationMetadataProvider.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultValidationMetadataProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultValidationMetadataProvider.cs index 03faa4be62..c8df349ccd 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultValidationMetadataProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Metadata/DefaultValidationMetadataProvider.cs @@ -4,15 +4,14 @@ using System; using System.Linq; using System.Reflection; -using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Metadata { /// /// A default implementation of . /// - public class DefaultValidationMetadataProvider : IValidationMetadataProvider + internal class DefaultValidationMetadataProvider : IValidationMetadataProvider { /// public void CreateValidationMetadata(ValidationMetadataProviderContext context) @@ -56,4 +55,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs index 4b7a53b498..c9d973db2b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBinderFactory.cs @@ -8,7 +8,6 @@ using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBindingHelper.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBindingHelper.cs index 90d8dd79f1..bc2f84b235 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ModelBindingHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ModelBindingHelper.cs @@ -14,9 +14,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.ModelBinding.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding { - public static class ModelBindingHelper + internal static class ModelBindingHelper { /// /// Updates the specified instance using the specified diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NoOpBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/NoOpBinder.cs similarity index 76% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NoOpBinder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/NoOpBinder.cs index 0fd7146fc3..7f591d6a8b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NoOpBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/NoOpBinder.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.ModelBinding; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding { - public class NoOpBinder : IModelBinder + internal class NoOpBinder : IModelBinder { public static readonly IModelBinder Instance = new NoOpBinder(); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ObjectModelValidator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ObjectModelValidator.cs index 6c34f35c2f..43785d55cd 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ObjectModelValidator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ObjectModelValidator.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; namespace Microsoft.AspNetCore.Mvc.ModelBinding @@ -101,9 +100,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding public abstract ValidationVisitor GetValidationVisitor( ActionContext actionContext, IModelValidatorProvider validatorProvider, -#pragma warning disable PUB0001 // Pubternal type in public API ValidatorCache validatorCache, -#pragma warning restore PUB0001 IModelMetadataProvider metadataProvider, ValidationStateDictionary validationState); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs index 0cf3693eb1..f0129749d9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ParameterBinder.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PlaceholderBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PlaceholderBinder.cs similarity index 84% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PlaceholderBinder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PlaceholderBinder.cs index 0e6bdc07a1..dc3d79618f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PlaceholderBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PlaceholderBinder.cs @@ -2,15 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.ModelBinding; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding { // Used as a placeholder to break cycles while building a tree of model binders in ModelBinderFactory. // // When a cycle is detected by a call to Create(...), we create an instance of this class and return it // to break the cycle. Later when the 'real' binder is created we set Inner to point to that. - public class PlaceholderBinder : IModelBinder + internal class PlaceholderBinder : IModelBinder { public IModelBinder Inner { get; set; } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PrefixContainer.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PrefixContainer.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PrefixContainer.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PrefixContainer.cs index ade8cc8102..aa4b0a6f6b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PrefixContainer.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PrefixContainer.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding { /// /// This is a container for prefix values. It normalizes all the values into dotted-form and then stores diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PropertyValueSetter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PropertyValueSetter.cs similarity index 89% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PropertyValueSetter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PropertyValueSetter.cs index a6983106da..353a39a724 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/PropertyValueSetter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/PropertyValueSetter.cs @@ -3,11 +3,10 @@ using System.Collections.Generic; using System.Reflection; -using Microsoft.AspNetCore.Mvc.ModelBinding; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding { - public static class PropertyValueSetter + internal static class PropertyValueSetter { private static readonly MethodInfo CallPropertyAddRangeOpenGenericMethod = typeof(PropertyValueSetter).GetMethod(nameof(CallPropertyAddRange), BindingFlags.NonPublic | BindingFlags.Static); @@ -58,8 +57,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal private static void CallPropertyAddRange(object target, object source) { var targetCollection = (ICollection)target; - var sourceCollection = source as IEnumerable; - if (sourceCollection != null && !targetCollection.IsReadOnly) + if (source is IEnumerable sourceCollection && !targetCollection.IsReadOnly) { targetCollection.Clear(); foreach (var item in sourceCollection) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs index e7d62e3852..9094a62dda 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/QueryStringValueProvider.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Globalization; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Internal; namespace Microsoft.AspNetCore.Mvc.ModelBinding { @@ -14,7 +13,6 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding /// public class QueryStringValueProvider : BindingSourceValueProvider, IEnumerableValueProvider { - private readonly CultureInfo _culture; private readonly IQueryCollection _values; private PrefixContainer _prefixContainer; @@ -41,14 +39,12 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding } _values = values; - _culture = culture; + Culture = culture; } - public CultureInfo Culture => _culture; + public CultureInfo Culture { get; } -#pragma warning disable PUB0001 // Pubternal type in public API protected PrefixContainer PrefixContainer -#pragma warning restore PUB0001 { get { @@ -86,6 +82,15 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding throw new ArgumentNullException(nameof(key)); } + if (key.Length == 0) + { + // Top level parameters will fall back to an empty prefix when the parameter name does not + // appear in any value provider. This would result in the parameter binding to a query string + // parameter with a empty key (e.g. /User?=test) which isn't a scenario we want to support. + // Return a "None" result in this event. + return ValueProviderResult.None; + } + var values = _values[key]; if (values.Count == 0) { @@ -93,7 +98,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding } else { - return new ValueProviderResult(values, _culture); + return new ValueProviderResult(values, Culture); } } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ReferenceEqualityComparer.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ReferenceEqualityComparer.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ReferenceEqualityComparer.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ReferenceEqualityComparer.cs index e2288a01c8..ec41a7f810 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ReferenceEqualityComparer.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/ReferenceEqualityComparer.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding { internal class ReferenceEqualityComparer : IEqualityComparer { @@ -31,4 +31,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal return RuntimeHelpers.GetHashCode(obj); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/RouteValueProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/RouteValueProvider.cs index 615b4bd437..66e1ea1c2e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/RouteValueProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/RouteValueProvider.cs @@ -3,7 +3,6 @@ using System; using System.Globalization; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Mvc.ModelBinding @@ -57,9 +56,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding Culture = culture; } -#pragma warning disable PUB0001 // Pubternal type in public API protected PrefixContainer PrefixContainer -#pragma warning restore PUB0001 { get { @@ -88,6 +85,15 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding throw new ArgumentNullException(nameof(key)); } + if (key.Length == 0) + { + // Top level parameters will fall back to an empty prefix when the parameter name does not + // appear in any value provider. This would result in the parameter binding to a route value + // an empty key which isn't a scenario we want to support. + // Return a "None" result in this event. + return ValueProviderResult.None; + } + if (_values.TryGetValue(key, out var value)) { var stringValue = value as string ?? Convert.ToString(value, Culture) ?? string.Empty; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ClientValidatorCache.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ClientValidatorCache.cs index 0bcc97f67b..2697daec71 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ClientValidatorCache.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ClientValidatorCache.cs @@ -5,10 +5,8 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { public class ClientValidatorCache { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCollectionValidationStrategy.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultCollectionValidationStrategy.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCollectionValidationStrategy.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultCollectionValidationStrategy.cs index 322f55d55b..95dc8db0e8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultCollectionValidationStrategy.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultCollectionValidationStrategy.cs @@ -5,12 +5,10 @@ using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Reflection; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using System.Linq.Expressions; +using System.Reflection; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { /// /// The default implementation of for a collection. @@ -18,28 +16,28 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// This implementation handles cases like: /// - /// Model: IList<Student> + /// Model: IList<Student> /// Query String: ?students[0].Age=8&students[1].Age=9 - /// + /// /// In this case the elements of the collection are identified in the input data set by an incrementing /// integer index. /// - /// + /// /// or: - /// + /// /// - /// Model: IDictionary<string, int> + /// Model: IDictionary<string, int> /// Query String: ?students[0].Key=Joey&students[0].Value=8 - /// + /// /// In this case the dictionary is treated as a collection of key-value pairs, and the elements of the /// collection are identified in the input data set by an incrementing integer index. /// - /// + /// /// Using this key format, the enumerator enumerates model objects of type matching /// . The indices of the elements in the collection are used to /// compute the model prefix keys. /// - public class DefaultCollectionValidationStrategy : IValidationStrategy + internal class DefaultCollectionValidationStrategy : IValidationStrategy { private static readonly MethodInfo _getEnumerator = typeof(DefaultCollectionValidationStrategy) .GetMethod(nameof(GetEnumerator), BindingFlags.Static | BindingFlags.NonPublic); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultComplexObjectValidationStrategy.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultComplexObjectValidationStrategy.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultComplexObjectValidationStrategy.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultComplexObjectValidationStrategy.cs index a2a1e0323a..f82ec567f1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultComplexObjectValidationStrategy.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultComplexObjectValidationStrategy.cs @@ -5,15 +5,13 @@ using System; using System.Collections; using System.Collections.Generic; using System.Reflection; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { /// /// The default implementation of for a complex object. /// - public class DefaultComplexObjectValidationStrategy : IValidationStrategy + internal class DefaultComplexObjectValidationStrategy : IValidationStrategy { private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultModelValidatorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultModelValidatorProvider.cs index 2174be1417..4abcdc4d44 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultModelValidatorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultModelValidatorProvider.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation /// The provides validators from /// instances in . /// - internal sealed class DefaultModelValidatorProvider : IMetadataBasedModelValidatorProvider + internal class DefaultModelValidatorProvider : IMetadataBasedModelValidatorProvider { /// public void CreateValidators(ModelValidatorProviderContext context) @@ -50,4 +50,4 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation return false; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DefaultObjectValidator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DefaultObjectValidator.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs index ff175dc5cf..102634f3f4 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/DefaultObjectValidator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs @@ -2,11 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { /// /// The default implementation of . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ExplicitIndexCollectionValidationStrategy.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ExplicitIndexCollectionValidationStrategy.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ExplicitIndexCollectionValidationStrategy.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ExplicitIndexCollectionValidationStrategy.cs index eb955d6964..4c63b2cbaa 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ExplicitIndexCollectionValidationStrategy.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ExplicitIndexCollectionValidationStrategy.cs @@ -4,10 +4,8 @@ using System; using System.Collections; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { /// /// An implementation of for a collection bound using 'explicit indexing' @@ -16,20 +14,20 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// /// This implementation handles cases like: /// - /// Model: IList<Student> + /// Model: IList<Student> /// Query String: ?students.index=Joey,Katherine&students[Joey].Age=8&students[Katherine].Age=9 - /// + /// /// In this case, 'Joey' and 'Katherine' need to be used in the model prefix keys, but cannot be inferred - /// form inspecting the collection. These prefixes are captured during model binding, and mapped to + /// form inspecting the collection. These prefixes are captured during model binding, and mapped to /// the corresponding ordinal index of a model object in the collection. The enumerator returned from this /// class will yield two 'Student' objects with corresponding keys 'students[Joey]' and 'students[Katherine]'. /// - /// + /// /// Using this key format, the enumerator enumerates model objects of type matching /// . The keys captured during model binding are mapped to the elements /// in the collection to compute the model prefix keys. /// - public class ExplicitIndexCollectionValidationStrategy : IValidationStrategy + internal class ExplicitIndexCollectionValidationStrategy : IValidationStrategy { /// /// Creates a new . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ShortFormDictionaryValidationStrategy.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ShortFormDictionaryValidationStrategy.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ShortFormDictionaryValidationStrategy.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ShortFormDictionaryValidationStrategy.cs index 31d1db97bf..5f79aae6f4 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ShortFormDictionaryValidationStrategy.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ShortFormDictionaryValidationStrategy.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { /// /// An implementation of for a dictionary bound with 'short form' style keys. @@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal /// Using this key format, the enumerator enumerates model objects of type . The /// keys of the dictionary are not validated as they must be simple types. /// - public class ShortFormDictionaryValidationStrategy : IValidationStrategy + internal class ShortFormDictionaryValidationStrategy : IValidationStrategy { private readonly ModelMetadata _valueMetadata; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ValidationStack.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationStack.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ValidationStack.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationStack.cs index ba24828544..de067ac450 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Internal/ValidationStack.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationStack.cs @@ -3,11 +3,10 @@ using System.Collections.Generic; using System.Diagnostics; -using Microsoft.AspNetCore.Mvc.Internal; -namespace Microsoft.AspNetCore.Mvc.ModelBinding.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { - public class ValidationStack + internal class ValidationStack { public int Count => HashSet?.Count ?? List.Count; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs index 0b277c68c6..681bdc4548 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidationVisitor.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation @@ -17,6 +15,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation /// public class ValidationVisitor { + private readonly ValidationStack _currentPath; private int? _maxValidationDepth; /// @@ -30,9 +29,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation public ValidationVisitor( ActionContext actionContext, IModelValidatorProvider validatorProvider, -#pragma warning disable PUB0001 // Pubternal type in public API ValidatorCache validatorCache, -#pragma warning restore PUB0001 IModelMetadataProvider metadataProvider, ValidationStateDictionary validationState) { @@ -59,20 +56,16 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation ValidationState = validationState; ModelState = actionContext.ModelState; - CurrentPath = new ValidationStack(); + _currentPath = new ValidationStack(); } protected IModelValidatorProvider ValidatorProvider { get; } protected IModelMetadataProvider MetadataProvider { get; } -#pragma warning disable PUB0001 // Pubternal type in public API + protected ValidatorCache Cache { get; } -#pragma warning restore PUB0001 protected ActionContext Context { get; } protected ModelStateDictionary ModelState { get; } protected ValidationStateDictionary ValidationState { get; } -#pragma warning disable PUB0001 // Pubternal type in public API - protected ValidationStack CurrentPath { get; } -#pragma warning restore PUB0001 protected object Container { get; set; } protected string Key { get; set; } @@ -221,18 +214,18 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { RuntimeHelpers.EnsureSufficientExecutionStack(); - if (model != null && !CurrentPath.Push(model)) + if (model != null && !_currentPath.Push(model)) { // This is a cycle, bail. return true; } - if (MaxValidationDepth != null && CurrentPath.Count > MaxValidationDepth) + if (MaxValidationDepth != null && _currentPath.Count > MaxValidationDepth) { // Non cyclic but too deep an object graph. // Pop the current model to make ValidationStack.Dispose happy - CurrentPath.Pop(model); + _currentPath.Pop(model); string message; switch (metadata.MetadataKind) @@ -268,7 +261,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { // Use the key on the entry, because we might not have entries in model state. SuppressValidation(entry.Key); - CurrentPath.Pop(model); + _currentPath.Pop(model); return true; } // If the metadata indicates that no validators exist AND the aggregate state for the key says that the model graph @@ -288,7 +281,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation } } - CurrentPath.Pop(model); + _currentPath.Pop(model); return true; } @@ -448,7 +441,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation _visitor.Model = _model; _visitor.Strategy = _strategy; - _visitor.CurrentPath.Pop(_newModel); + _visitor._currentPath.Pop(_newModel); } } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ValidatorCache.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidatorCache.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ValidatorCache.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidatorCache.cs index 61e8303d40..5fadd38e29 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ValidatorCache.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Validation/ValidatorCache.cs @@ -5,10 +5,8 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.ModelBinding.Validation { public class ValidatorCache { @@ -16,8 +14,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal public IReadOnlyList GetValidators(ModelMetadata metadata, IModelValidatorProvider validatorProvider) { - CacheEntry entry; - if (_cacheEntries.TryGetValue(metadata, out entry)) + if (_cacheEntries.TryGetValue(metadata, out var entry)) { return GetValidatorsFromEntry(entry, metadata, validatorProvider); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreDiagnosticSourceExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreDiagnosticSourceExtensions.cs new file mode 100644 index 0000000000..32085e7da8 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreDiagnosticSourceExtensions.cs @@ -0,0 +1,1000 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Routing; + +namespace Microsoft.AspNetCore.Mvc +{ + // We're doing a lot of asserts here because these methods are really tedious to test and + // highly dependent on the details of the invoker's state machine. Basically if we wrote the + // obvious unit tests that would generate a lot of boilerplate and wouldn't cover the hard parts. + internal static class MvcCoreDiagnosticSourceExtensions + { + public static void BeforeAction( + this DiagnosticListener diagnosticListener, + ActionDescriptor actionDescriptor, + HttpContext httpContext, + RouteData routeData) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionDescriptor != null); + Debug.Assert(httpContext != null); + Debug.Assert(routeData != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeActionImpl(diagnosticListener, actionDescriptor, httpContext, routeData); + } + } + + private static void BeforeActionImpl(DiagnosticListener diagnosticListener, ActionDescriptor actionDescriptor, HttpContext httpContext, RouteData routeData) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeAction")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeAction", + new { actionDescriptor, httpContext = httpContext, routeData = routeData }); + } + } + + public static void AfterAction( + this DiagnosticListener diagnosticListener, + ActionDescriptor actionDescriptor, + HttpContext httpContext, + RouteData routeData) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionDescriptor != null); + Debug.Assert(httpContext != null); + Debug.Assert(routeData != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterActionImpl(diagnosticListener, actionDescriptor, httpContext, routeData); + } + } + + private static void AfterActionImpl(DiagnosticListener diagnosticListener, ActionDescriptor actionDescriptor, HttpContext httpContext, RouteData routeData) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterAction")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterAction", + new { actionDescriptor, httpContext = httpContext, routeData = routeData }); + } + } + + public static void BeforeOnAuthorizationAsync( + this DiagnosticListener diagnosticListener, + AuthorizationFilterContext authorizationContext, + IAsyncAuthorizationFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(authorizationContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnAuthorizationAsyncImpl(diagnosticListener, authorizationContext, filter); + } + } + + private static void BeforeOnAuthorizationAsyncImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", + new + { + actionDescriptor = authorizationContext.ActionDescriptor, + authorizationContext = authorizationContext, + filter = filter + }); + } + } + + public static void AfterOnAuthorizationAsync( + this DiagnosticListener diagnosticListener, + AuthorizationFilterContext authorizationContext, + IAsyncAuthorizationFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(authorizationContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnAuthorizationAsyncImpl(diagnosticListener, authorizationContext, filter); + } + } + + private static void AfterOnAuthorizationAsyncImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAsyncAuthorizationFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnAuthorization", + new + { + actionDescriptor = authorizationContext.ActionDescriptor, + authorizationContext = authorizationContext, + filter = filter + }); + } + } + + public static void BeforeOnAuthorization( + this DiagnosticListener diagnosticListener, + AuthorizationFilterContext authorizationContext, + IAuthorizationFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(authorizationContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnAuthorizationImpl(diagnosticListener, authorizationContext, filter); + } + } + + private static void BeforeOnAuthorizationImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAuthorizationFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnAuthorization")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnAuthorization", + new + { + actionDescriptor = authorizationContext.ActionDescriptor, + authorizationContext = authorizationContext, + filter = filter + }); + } + } + + public static void AfterOnAuthorization( + this DiagnosticListener diagnosticListener, + AuthorizationFilterContext authorizationContext, + IAuthorizationFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(authorizationContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnAuthorizationImpl(diagnosticListener, authorizationContext, filter); + } + } + + private static void AfterOnAuthorizationImpl(DiagnosticListener diagnosticListener, AuthorizationFilterContext authorizationContext, IAuthorizationFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnAuthorization")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnAuthorization", + new + { + actionDescriptor = authorizationContext.ActionDescriptor, + authorizationContext = authorizationContext, + filter = filter + }); + } + } + + public static void BeforeOnResourceExecution( + this DiagnosticListener diagnosticListener, + ResourceExecutingContext resourceExecutingContext, + IAsyncResourceFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resourceExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnResourceExecutionImpl(diagnosticListener, resourceExecutingContext, filter); + } + } + + private static void BeforeOnResourceExecutionImpl(DiagnosticListener diagnosticListener, ResourceExecutingContext resourceExecutingContext, IAsyncResourceFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecution", + new + { + actionDescriptor = resourceExecutingContext.ActionDescriptor, + resourceExecutingContext = resourceExecutingContext, + filter = filter + }); + } + } + + public static void AfterOnResourceExecution( + this DiagnosticListener diagnosticListener, + ResourceExecutedContext resourceExecutedContext, + IAsyncResourceFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resourceExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnResourceExecutionImpl(diagnosticListener, resourceExecutedContext, filter); + } + } + + private static void AfterOnResourceExecutionImpl(DiagnosticListener diagnosticListener, ResourceExecutedContext resourceExecutedContext, IAsyncResourceFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnResourceExecution", + new + { + actionDescriptor = resourceExecutedContext.ActionDescriptor, + resourceExecutedContext = resourceExecutedContext, + filter = filter + }); + } + } + + public static void BeforeOnResourceExecuting( + this DiagnosticListener diagnosticListener, + ResourceExecutingContext resourceExecutingContext, + IResourceFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resourceExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnResourceExecutingImpl(diagnosticListener, resourceExecutingContext, filter); + } + } + + private static void BeforeOnResourceExecutingImpl(DiagnosticListener diagnosticListener, ResourceExecutingContext resourceExecutingContext, IResourceFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting", + new + { + actionDescriptor = resourceExecutingContext.ActionDescriptor, + resourceExecutingContext = resourceExecutingContext, + filter = filter + }); + } + } + + public static void AfterOnResourceExecuting( + this DiagnosticListener diagnosticListener, + ResourceExecutingContext resourceExecutingContext, + IResourceFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resourceExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnResourceExecutingImpl(diagnosticListener, resourceExecutingContext, filter); + } + } + + private static void AfterOnResourceExecutingImpl(DiagnosticListener diagnosticListener, ResourceExecutingContext resourceExecutingContext, IResourceFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting", + new + { + actionDescriptor = resourceExecutingContext.ActionDescriptor, + resourceExecutingContext = resourceExecutingContext, + filter = filter + }); + } + } + + public static void BeforeOnResourceExecuted( + this DiagnosticListener diagnosticListener, + ResourceExecutedContext resourceExecutedContext, + IResourceFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resourceExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnResourceExecutedImpl(diagnosticListener, resourceExecutedContext, filter); + } + } + + private static void BeforeOnResourceExecutedImpl(DiagnosticListener diagnosticListener, ResourceExecutedContext resourceExecutedContext, IResourceFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted", + new + { + actionDescriptor = resourceExecutedContext.ActionDescriptor, + resourceExecutedContext = resourceExecutedContext, + filter = filter + }); + } + } + + public static void AfterOnResourceExecuted( + this DiagnosticListener diagnosticListener, + ResourceExecutedContext resourceExecutedContext, + IResourceFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resourceExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnResourceExecutedImpl(diagnosticListener, resourceExecutedContext, filter); + } + } + + private static void AfterOnResourceExecutedImpl(DiagnosticListener diagnosticListener, ResourceExecutedContext resourceExecutedContext, IResourceFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted", + new + { + actionDescriptor = resourceExecutedContext.ActionDescriptor, + resourceExecutedContext = resourceExecutedContext, + filter = filter + }); + } + } + + public static void BeforeOnExceptionAsync( + this DiagnosticListener diagnosticListener, + ExceptionContext exceptionContext, + IAsyncExceptionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(exceptionContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnExceptionAsyncImpl(diagnosticListener, exceptionContext, filter); + } + } + + private static void BeforeOnExceptionAsyncImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IAsyncExceptionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnException", + new + { + actionDescriptor = exceptionContext.ActionDescriptor, + exceptionContext = exceptionContext, + filter = filter + }); + } + } + + public static void AfterOnExceptionAsync( + this DiagnosticListener diagnosticListener, + ExceptionContext exceptionContext, + IAsyncExceptionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(exceptionContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnExceptionAsyncImpl(diagnosticListener, exceptionContext, filter); + } + } + + private static void AfterOnExceptionAsyncImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IAsyncExceptionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnException", + new + { + actionDescriptor = exceptionContext.ActionDescriptor, + exceptionContext = exceptionContext, + filter = filter + }); + } + } + + public static void BeforeOnException( + this DiagnosticListener diagnosticListener, + ExceptionContext exceptionContext, + IExceptionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(exceptionContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnExceptionImpl(diagnosticListener, exceptionContext, filter); + } + } + + private static void BeforeOnExceptionImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IExceptionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnException")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnException", + new + { + actionDescriptor = exceptionContext.ActionDescriptor, + exceptionContext = exceptionContext, + filter = filter + }); + } + } + + public static void AfterOnException( + this DiagnosticListener diagnosticListener, + ExceptionContext exceptionContext, + IExceptionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(exceptionContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnExceptionImpl(diagnosticListener, exceptionContext, filter); + } + } + + private static void AfterOnExceptionImpl(DiagnosticListener diagnosticListener, ExceptionContext exceptionContext, IExceptionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnException")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnException", + new + { + actionDescriptor = exceptionContext.ActionDescriptor, + exceptionContext = exceptionContext, + filter = filter + }); + } + } + + public static void BeforeOnActionExecution( + this DiagnosticListener diagnosticListener, + ActionExecutingContext actionExecutingContext, + IAsyncActionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnActionExecutionImpl(diagnosticListener, actionExecutingContext, filter); + } + } + + private static void BeforeOnActionExecutionImpl(DiagnosticListener diagnosticListener, ActionExecutingContext actionExecutingContext, IAsyncActionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnActionExecution", + new + { + actionDescriptor = actionExecutingContext.ActionDescriptor, + actionExecutingContext = actionExecutingContext, + filter = filter + }); + } + } + + public static void AfterOnActionExecution( + this DiagnosticListener diagnosticListener, + ActionExecutedContext actionExecutedContext, + IAsyncActionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnActionExecutionImpl(diagnosticListener, actionExecutedContext, filter); + } + } + + private static void AfterOnActionExecutionImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IAsyncActionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnActionExecution", + new + { + actionDescriptor = actionExecutedContext.ActionDescriptor, + actionExecutedContext = actionExecutedContext, + filter = filter + }); + } + } + + public static void BeforeOnActionExecuting( + this DiagnosticListener diagnosticListener, + ActionExecutingContext actionExecutingContext, + IActionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnActionExecutingImpl(diagnosticListener, actionExecutingContext, filter); + } + } + + private static void BeforeOnActionExecutingImpl(DiagnosticListener diagnosticListener, ActionExecutingContext actionExecutingContext, IActionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting", + new + { + actionDescriptor = actionExecutingContext.ActionDescriptor, + actionExecutingContext = actionExecutingContext, + filter = filter + }); + } + } + + public static void AfterOnActionExecuting( + this DiagnosticListener diagnosticListener, + ActionExecutingContext actionExecutingContext, + IActionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnActionExecutingImpl(diagnosticListener, actionExecutingContext, filter); + } + } + + private static void AfterOnActionExecutingImpl(DiagnosticListener diagnosticListener, ActionExecutingContext actionExecutingContext, IActionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnActionExecuting", + new + { + actionDescriptor = actionExecutingContext.ActionDescriptor, + actionExecutingContext = actionExecutingContext, + filter = filter + }); + } + } + + public static void BeforeOnActionExecuted( + this DiagnosticListener diagnosticListener, + ActionExecutedContext actionExecutedContext, + IActionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnActionExecutedImpl(diagnosticListener, actionExecutedContext, filter); + } + } + + private static void BeforeOnActionExecutedImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IActionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted", + new + { + actionDescriptor = actionExecutedContext.ActionDescriptor, + actionExecutedContext = actionExecutedContext, + filter = filter + }); + } + } + + public static void AfterOnActionExecuted( + this DiagnosticListener diagnosticListener, + ActionExecutedContext actionExecutedContext, + IActionFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnActionExecutedImpl(diagnosticListener, actionExecutedContext, filter); + } + } + + private static void AfterOnActionExecutedImpl(DiagnosticListener diagnosticListener, ActionExecutedContext actionExecutedContext, IActionFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnActionExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnActionExecuted", + new + { + actionDescriptor = actionExecutedContext.ActionDescriptor, + actionExecutedContext = actionExecutedContext, + filter = filter + }); + } + } + + public static void BeforeActionMethod( + this DiagnosticListener diagnosticListener, + ActionContext actionContext, + IDictionary actionArguments, + object controller) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionContext != null); + Debug.Assert(actionArguments != null); + Debug.Assert(controller != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeActionMethodImpl(diagnosticListener, actionContext, actionArguments, controller); + } + } + + private static void BeforeActionMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IDictionary actionArguments, object controller) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionMethod")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeActionMethod", + new + { + actionContext = actionContext, + arguments = actionArguments, + controller = controller + }); + } + } + + public static void AfterActionMethod( + this DiagnosticListener diagnosticListener, + ActionContext actionContext, + IDictionary actionArguments, + object controller, + IActionResult result) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionContext != null); + Debug.Assert(actionArguments != null); + Debug.Assert(controller != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterActionMethodImpl(diagnosticListener, actionContext, actionArguments, controller, result); + } + } + + private static void AfterActionMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IDictionary actionArguments, object controller, IActionResult result) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionMethod")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterActionMethod", + new + { + actionContext = actionContext, + arguments = actionArguments, + controller = controller, + result = result + }); + } + } + + public static void BeforeOnResultExecution( + this DiagnosticListener diagnosticListener, + ResultExecutingContext resultExecutingContext, + IAsyncResultFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resultExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnResultExecutionImpl(diagnosticListener, resultExecutingContext, filter); + } + } + + private static void BeforeOnResultExecutionImpl(DiagnosticListener diagnosticListener, ResultExecutingContext resultExecutingContext, IAsyncResultFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnResultExecution", + new + { + actionDescriptor = resultExecutingContext.ActionDescriptor, + resultExecutingContext = resultExecutingContext, + filter = filter + }); + } + } + + public static void AfterOnResultExecution( + this DiagnosticListener diagnosticListener, + ResultExecutedContext resultExecutedContext, + IAsyncResultFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resultExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnResultExecutionImpl(diagnosticListener, resultExecutedContext, filter); + } + } + + private static void AfterOnResultExecutionImpl(DiagnosticListener diagnosticListener, ResultExecutedContext resultExecutedContext, IAsyncResultFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnResultExecution", + new + { + actionDescriptor = resultExecutedContext.ActionDescriptor, + resultExecutedContext = resultExecutedContext, + filter = filter + }); + } + } + + public static void BeforeOnResultExecuting( + this DiagnosticListener diagnosticListener, + ResultExecutingContext resultExecutingContext, + IResultFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resultExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnResultExecutingImpl(diagnosticListener, resultExecutingContext, filter); + } + } + + private static void BeforeOnResultExecutingImpl(DiagnosticListener diagnosticListener, ResultExecutingContext resultExecutingContext, IResultFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting", + new + { + actionDescriptor = resultExecutingContext.ActionDescriptor, + resultExecutingContext = resultExecutingContext, + filter = filter + }); + } + } + + public static void AfterOnResultExecuting( + this DiagnosticListener diagnosticListener, + ResultExecutingContext resultExecutingContext, + IResultFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resultExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnResultExecutingImpl(diagnosticListener, resultExecutingContext, filter); + } + } + + private static void AfterOnResultExecutingImpl(DiagnosticListener diagnosticListener, ResultExecutingContext resultExecutingContext, IResultFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnResultExecuting", + new + { + actionDescriptor = resultExecutingContext.ActionDescriptor, + resultExecutingContext = resultExecutingContext, + filter = filter + }); + } + } + + public static void BeforeOnResultExecuted( + this DiagnosticListener diagnosticListener, + ResultExecutedContext resultExecutedContext, + IResultFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resultExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnResultExecutedImpl(diagnosticListener, resultExecutedContext, filter); + } + } + + private static void BeforeOnResultExecutedImpl(DiagnosticListener diagnosticListener, ResultExecutedContext resultExecutedContext, IResultFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted", + new + { + actionDescriptor = resultExecutedContext.ActionDescriptor, + resultExecutedContext = resultExecutedContext, + filter = filter + }); + } + } + + public static void AfterOnResultExecuted( + this DiagnosticListener diagnosticListener, + ResultExecutedContext resultExecutedContext, + IResultFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(resultExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnResultExecutedImpl(diagnosticListener, resultExecutedContext, filter); + } + } + + private static void AfterOnResultExecutedImpl(DiagnosticListener diagnosticListener, ResultExecutedContext resultExecutedContext, IResultFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnResultExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnResultExecuted", + new + { + actionDescriptor = resultExecutedContext.ActionDescriptor, + resultExecutedContext = resultExecutedContext, + filter = filter + }); + } + } + + public static void BeforeActionResult( + this DiagnosticListener diagnosticListener, + ActionContext actionContext, + IActionResult result) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionContext != null); + Debug.Assert(result != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeActionResultImpl(diagnosticListener, actionContext, result); + } + } + + private static void BeforeActionResultImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IActionResult result) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeActionResult")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeActionResult", + new { actionContext = actionContext, result = result }); + } + } + + public static void AfterActionResult( + this DiagnosticListener diagnosticListener, + ActionContext actionContext, + IActionResult result) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionContext != null); + Debug.Assert(result != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterActionResultImpl(diagnosticListener, actionContext, result); + } + } + + private static void AfterActionResultImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, IActionResult result) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterActionResult")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterActionResult", + new { actionContext = actionContext, result = result }); + } + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreLoggerExtensions.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreLoggerExtensions.cs index b4a223b8b2..e731b3be50 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcCoreLoggerExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreLoggerExtensions.cs @@ -15,14 +15,13 @@ using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.AspNetCore.Mvc.Formatters.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc { internal static class MvcCoreLoggerExtensions { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs index c83dc1442a..27a02b4d94 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/PhysicalFileResult.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ProducesAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ProducesAttribute.cs index e9346f7330..41d1815bd9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ProducesAttribute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ProducesAttribute.cs @@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Formatters; -using Microsoft.AspNetCore.Mvc.Formatters.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs index 6aae329d12..4fcd46a1d1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectResult.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs index 7e48ac38c3..06de942c13 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToActionResult.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs index 4728a4a08c..5f82cd50df 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToPageResult.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs index 500d8f3d2f..8966eab50e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RedirectToRouteResult.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestFormLimitsAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestFormLimitsAttribute.cs index d1f1c73578..0681091231 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestFormLimitsAttribute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestFormLimitsAttribute.cs @@ -6,7 +6,6 @@ using System.IO; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestSizeLimitAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestSizeLimitAttribute.cs index 95063ff857..a9a6098f65 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestSizeLimitAttribute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/RequestSizeLimitAttribute.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs index a3e2d6aaf4..a647be106f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/ResponseCacheAttribute.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/ActionConstraintMatcherPolicy.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/ActionConstraintMatcherPolicy.cs index d31e06daf4..f71c3294e3 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/ActionConstraintMatcherPolicy.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/ActionConstraintMatcherPolicy.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ActionConstraints; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Matching; @@ -68,7 +67,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing { // This one is OK, we implement this in endpoint routing. } - else if (actionConstraint.GetType().FullName == "Microsoft.AspNetCore.Mvc.Cors.Internal.CorsHttpMethodActionConstraint") + else if (actionConstraint.GetType().FullName == "Microsoft.AspNetCore.Mvc.Cors.CorsHttpMethodActionConstraint") { // This one is OK, we implement this in endpoint routing. } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/AttributeRoute.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/AttributeRoute.cs index 9d307e7e23..da0fc4594e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRoute.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/AttributeRoute.cs @@ -14,9 +14,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { - public class AttributeRoute : IRouter + internal class AttributeRoute : IRouter { private readonly IActionDescriptorCollectionProvider _actionDescriptorCollectionProvider; private readonly IServiceProvider _services; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRouting.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/AttributeRouting.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRouting.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/AttributeRouting.cs index e5bf2d5ec4..66804ba63a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/AttributeRouting.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/AttributeRouting.cs @@ -6,9 +6,9 @@ using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { - public static class AttributeRouting + internal static class AttributeRouting { /// /// Creates an attribute route using the provided services and provided target router. @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal return new AttributeRoute( services.GetRequiredService(), services, - actions => + actions => { var handler = services.GetRequiredService(); handler.Actions = actions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcAttributeRouteHandler.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcAttributeRouteHandler.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcAttributeRouteHandler.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcAttributeRouteHandler.cs index c40318e2d9..f32032f760 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcAttributeRouteHandler.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcAttributeRouteHandler.cs @@ -10,29 +10,29 @@ using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging; using Resources = Microsoft.AspNetCore.Mvc.Core.Resources; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { - public class MvcAttributeRouteHandler : IRouter + internal class MvcAttributeRouteHandler : IRouter { private readonly IActionContextAccessor _actionContextAccessor; private readonly IActionInvokerFactory _actionInvokerFactory; private readonly IActionSelector _actionSelector; private readonly ILogger _logger; - private DiagnosticSource _diagnosticSource; + private DiagnosticListener _diagnosticListener; public MvcAttributeRouteHandler( IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory) - : this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null) + : this(actionInvokerFactory, actionSelector, diagnosticListener, loggerFactory, actionContextAccessor: null) { } public MvcAttributeRouteHandler( IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, IActionContextAccessor actionContextAccessor) { @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _actionInvokerFactory = actionInvokerFactory; _actionSelector = actionSelector; - _diagnosticSource = diagnosticSource; + _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); } @@ -69,7 +69,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal if (Actions == null) { var message = Resources.FormatPropertyOfTypeCannotBeNull( - nameof(Actions), + nameof(Actions), nameof(MvcAttributeRouteHandler)); throw new InvalidOperationException(message); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointDataSource.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcEndpointDataSource.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointDataSource.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcEndpointDataSource.cs index df110bee25..53e37a4595 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointDataSource.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcEndpointDataSource.cs @@ -10,13 +10,15 @@ using System.Threading; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.ActionConstraints; +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { internal class MvcEndpointDataSource : EndpointDataSource { @@ -57,6 +59,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _parameterPolicyFactory = parameterPolicyFactory; ConventionalEndpointInfos = new List(); + AttributeRoutingConventionResolvers = new List>(); // IMPORTANT: this needs to be the last thing we do in the constructor. Change notifications can happen immediately! // @@ -72,6 +75,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal public List ConventionalEndpointInfos { get; } + public List> AttributeRoutingConventionResolvers { get; } + public override IReadOnlyList Endpoints { get @@ -164,11 +169,20 @@ namespace Microsoft.AspNetCore.Mvc.Internal endpointInfo.DataTokens, endpointInfo.ParameterPolicies, suppressLinkGeneration: false, - suppressPathMatching: false); + suppressPathMatching: false, + endpointInfo.Conventions); } } else { + var conventionBuilder = ResolveActionConventionBuilder(action); + if (conventionBuilder == null) + { + // No convention builder for this action + // Do not create an endpoint for it + continue; + } + var attributeRoutePattern = RoutePatternFactory.Parse(action.AttributeRouteInfo.Template); CreateEndpoints( @@ -183,7 +197,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal dataTokens: null, allParameterPolicies: null, action.AttributeRouteInfo.SuppressLinkGeneration, - action.AttributeRouteInfo.SuppressPathMatching); + action.AttributeRouteInfo.SuppressPathMatching, + conventionBuilder.Conventions); } } @@ -205,6 +220,20 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } + private DefaultEndpointConventionBuilder ResolveActionConventionBuilder(ActionDescriptor action) + { + foreach (var filter in AttributeRoutingConventionResolvers) + { + var conventionBuilder = filter(action); + if (conventionBuilder != null) + { + return conventionBuilder; + } + } + + return null; + } + // CreateEndpoints processes the route pattern, replacing area/controller/action parameters with endpoint values // Because of default values it is possible for a route pattern to resolve to multiple endpoints private int CreateEndpoints( @@ -219,7 +248,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal RouteValueDictionary dataTokens, IDictionary> allParameterPolicies, bool suppressLinkGeneration, - bool suppressPathMatching) + bool suppressPathMatching, + List> conventions) { var newPathSegments = routePattern.PathSegments.ToList(); var hasLinkGenerationEndpoint = false; @@ -264,7 +294,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal routeOrder++, dataTokens, suppressLinkGeneration, - true); + true, + conventions); endpoints.Add(ep); hasLinkGenerationEndpoint = true; @@ -282,7 +313,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal routeOrder++, dataTokens, suppressLinkGeneration, - suppressPathMatching); + suppressPathMatching, + conventions); endpoints.Add(subEndpoint); } @@ -299,7 +331,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal routeOrder++, dataTokens, suppressLinkGeneration, - suppressPathMatching); + suppressPathMatching, + conventions); endpoints.Add(finalEndpoint); return routeOrder; @@ -406,6 +439,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal { newPathSegments[i] = RoutePatternFactory.Segment(segmentParts); } + } private bool UseDefaultValuePlusRemainingSegmentsOptional( @@ -536,7 +570,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal int order, RouteValueDictionary dataTokens, bool suppressLinkGeneration, - bool suppressPathMatching) + bool suppressPathMatching, + List> conventions) { RequestDelegate requestDelegate = (context) => { @@ -551,7 +586,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal var defaults = new RouteValueDictionary(nonInlineDefaults); EnsureRequiredValuesInDefaults(actionRouteValues, defaults, segments); - var metadataCollection = BuildEndpointMetadata( + var model = new RouteEndpointModel(requestDelegate, RoutePatternFactory.Pattern(patternRawText, defaults, parameterPolicies: null, segments), order); + + AddEndpointMetadata( + model.Metadata, action, routeName, new RouteValueDictionary(actionRouteValues), @@ -559,17 +597,23 @@ namespace Microsoft.AspNetCore.Mvc.Internal suppressLinkGeneration, suppressPathMatching); - var endpoint = new RouteEndpoint( - requestDelegate, - RoutePatternFactory.Pattern(patternRawText, defaults, parameterPolicies: null, segments), - order, - metadataCollection, - action.DisplayName); + model.DisplayName = action.DisplayName; - return endpoint; + // REVIEW: When should conventions be run + // Metadata should have lower precedence that data source metadata + if (conventions != null) + { + foreach (var convention in conventions) + { + convention(model); + } + } + + return (RouteEndpoint)model.Build(); } - private static EndpointMetadataCollection BuildEndpointMetadata( + private static void AddEndpointMetadata( + IList metadata, ActionDescriptor action, string routeName, RouteValueDictionary requiredValues, @@ -577,12 +621,13 @@ namespace Microsoft.AspNetCore.Mvc.Internal bool suppressLinkGeneration, bool suppressPathMatching) { - var metadata = new List(); - // Add action metadata first so it has a low precedence if (action.EndpointMetadata != null) { - metadata.AddRange(action.EndpointMetadata); + foreach (var d in action.EndpointMetadata) + { + metadata.Add(d); + } } metadata.Add(action); @@ -597,8 +642,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal // Add filter descriptors to endpoint metadata if (action.FilterDescriptors != null && action.FilterDescriptors.Count > 0) { - metadata.AddRange(action.FilterDescriptors.OrderBy(f => f, FilterDescriptorOrderComparer.Comparer) - .Select(f => f.Filter)); + foreach (var filter in action.FilterDescriptors.OrderBy(f => f, FilterDescriptorOrderComparer.Comparer).Select(f => f.Filter)) + { + metadata.Add(filter); + } } if (action.ActionConstraints != null && action.ActionConstraints.Count > 0) @@ -637,9 +684,6 @@ namespace Microsoft.AspNetCore.Mvc.Internal { metadata.Add(new SuppressMatchingMetadata()); } - - var metadataCollection = new EndpointMetadataCollection(metadata); - return metadataCollection; } // Ensure route values are a subset of defaults @@ -670,4 +714,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointInvokerFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcEndpointInvokerFactory.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointInvokerFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcEndpointInvokerFactory.cs index 3737a3b718..f0d608b168 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointInvokerFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcEndpointInvokerFactory.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Infrastructure; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { internal sealed class MvcEndpointInvokerFactory : IActionInvokerFactory { @@ -38,4 +38,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal return _invokerFactory.CreateInvoker(actionContext); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcRouteHandler.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcRouteHandler.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcRouteHandler.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcRouteHandler.cs index 21903703fa..3d7e1add1e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcRouteHandler.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/MvcRouteHandler.cs @@ -9,29 +9,29 @@ using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { - public class MvcRouteHandler : IRouter + internal class MvcRouteHandler : IRouter { private readonly IActionContextAccessor _actionContextAccessor; private readonly IActionInvokerFactory _actionInvokerFactory; private readonly IActionSelector _actionSelector; private readonly ILogger _logger; - private readonly DiagnosticSource _diagnosticSource; + private readonly DiagnosticListener _diagnosticListener; public MvcRouteHandler( IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory) - : this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null) + : this(actionInvokerFactory, actionSelector, diagnosticListener, loggerFactory, actionContextAccessor: null) { } public MvcRouteHandler( IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, IActionContextAccessor actionContextAccessor) { @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal _actionInvokerFactory = actionInvokerFactory; _actionSelector = actionSelector; - _diagnosticSource = diagnosticSource; + _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); } @@ -101,4 +101,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal return Task.CompletedTask; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NormalizedRouteValue.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/NormalizedRouteValue.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NormalizedRouteValue.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/NormalizedRouteValue.cs index 3013ee3171..9258332d0b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NormalizedRouteValue.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/NormalizedRouteValue.cs @@ -4,9 +4,9 @@ using System; using System.Globalization; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { - public static class NormalizedRouteValue + internal static class NormalizedRouteValue { /// /// Gets the case-normalized route value for the specified route . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NullRouter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/NullRouter.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NullRouter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/NullRouter.cs index c1b800c5bd..f359bd1841 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/NullRouter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/NullRouter.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Routing; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { internal class NullRouter : IRouter { @@ -24,4 +24,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal return Task.CompletedTask; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RoutePatternWriter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/RoutePatternWriter.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RoutePatternWriter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/RoutePatternWriter.cs index 3f0e0f6445..5f0e15b376 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/RoutePatternWriter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/RoutePatternWriter.cs @@ -3,11 +3,10 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; using Microsoft.AspNetCore.Routing.Patterns; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { internal static class RoutePatternWriter { @@ -76,4 +75,4 @@ namespace Microsoft.AspNetCore.Mvc.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/UrlHelperBase.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/UrlHelperBase.cs index 8e84b081b3..2cea4a9fc7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/UrlHelperBase.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/UrlHelperBase.cs @@ -8,7 +8,6 @@ using System.Globalization; using System.Text; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Mvc.Routing diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ViewEnginePath.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/ViewEnginePath.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ViewEnginePath.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/ViewEnginePath.cs index 29d4f85597..f24bdf7eca 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Internal/ViewEnginePath.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/Routing/ViewEnginePath.cs @@ -7,9 +7,9 @@ using System.Diagnostics; using System.Text; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.Internal +namespace Microsoft.AspNetCore.Mvc.Routing { - public static class ViewEnginePath + internal static class ViewEnginePath { public static readonly char[] PathSeparators = new[] { '/', '\\' }; private const string CurrentDirectoryToken = "."; @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal } string result; - + // Get directory name (including final slash) but do not use Path.GetDirectoryName() to preserve path // normalization. var index = first.LastIndexOf('/'); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignInResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignInResult.cs index 040bbe040d..d7bdfd3867 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignInResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignInResult.cs @@ -6,7 +6,6 @@ using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs index f972b9475c..0f69354784 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/SignOutResult.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc.Core; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs index 70de9cdafe..2f367817bd 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/StatusCodeResult.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs index 2e37c94a89..b7743795a0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/VirtualFileResult.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Net.Http.Headers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/breakingchanges.netcore.json b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/breakingchanges.netcore.json index 3fd0e6ddff..88e1b38758 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/breakingchanges.netcore.json +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Core/breakingchanges.netcore.json @@ -2,5 +2,75 @@ { "TypeId": "public class Microsoft.AspNetCore.Mvc.ApiControllerAttribute : Microsoft.AspNetCore.Mvc.ControllerAttribute, Microsoft.AspNetCore.Mvc.Internal.IApiBehaviorMetadata", "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.ConsumesAttribute : System.Attribute, Microsoft.AspNetCore.Mvc.Filters.IResourceFilter, Microsoft.AspNetCore.Mvc.Internal.IConsumesActionConstraint, Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestMetadataProvider", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider : Microsoft.AspNetCore.Mvc.Controllers.IControllerFactoryProvider", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerActivator : Microsoft.AspNetCore.Mvc.Controllers.IControllerActivator", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory : Microsoft.AspNetCore.Mvc.Controllers.IControllerFactory", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Formatters.FormatFilter : Microsoft.AspNetCore.Mvc.Formatters.Internal.IFormatFilter, Microsoft.AspNetCore.Mvc.Filters.IResourceFilter, Microsoft.AspNetCore.Mvc.Filters.IResultFilter", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.ModelBinding.FormValueProvider : Microsoft.AspNetCore.Mvc.ModelBinding.BindingSourceValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IEnumerableValueProvider", + "MemberId": "protected Microsoft.AspNetCore.Mvc.Internal.PrefixContainer get_PrefixContainer()", + "Kind": "Removal" + }, + { + "TypeId": "public abstract class Microsoft.AspNetCore.Mvc.ModelBinding.JQueryValueProvider : Microsoft.AspNetCore.Mvc.ModelBinding.BindingSourceValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IEnumerableValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IKeyRewriterValueProvider", + "MemberId": "protected Microsoft.AspNetCore.Mvc.Internal.PrefixContainer get_PrefixContainer()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.ModelBinding.QueryStringValueProvider : Microsoft.AspNetCore.Mvc.ModelBinding.BindingSourceValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IEnumerableValueProvider", + "MemberId": "protected Microsoft.AspNetCore.Mvc.Internal.PrefixContainer get_PrefixContainer()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.ModelBinding.RouteValueProvider : Microsoft.AspNetCore.Mvc.ModelBinding.BindingSourceValueProvider", + "MemberId": "protected Microsoft.AspNetCore.Mvc.Internal.PrefixContainer get_PrefixContainer()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor", + "MemberId": "protected Microsoft.AspNetCore.Mvc.Internal.ValidatorCache get_Cache()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor", + "MemberId": "protected Microsoft.AspNetCore.Mvc.ModelBinding.Internal.ValidationStack get_CurrentPath()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor", + "MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.ActionContext actionContext, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IModelValidatorProvider validatorProvider, Microsoft.AspNetCore.Mvc.Internal.ValidatorCache validatorCache, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider metadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationStateDictionary validationState)", + "Kind": "Removal" + }, + { + "TypeId": "public abstract class Microsoft.AspNetCore.Mvc.ModelBinding.ObjectModelValidator : Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator", + "MemberId": "public abstract Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor GetValidationVisitor(Microsoft.AspNetCore.Mvc.ActionContext actionContext, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IModelValidatorProvider validatorProvider, Microsoft.AspNetCore.Mvc.Internal.ValidatorCache validatorCache, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider metadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationStateDictionary validationState)", + "Kind": "Removal" + }, + { + "TypeId": "public struct Microsoft.AspNetCore.Mvc.Formatters.MediaType", + "MemberId": "public static Microsoft.AspNetCore.Mvc.Formatters.Internal.MediaTypeSegmentWithQuality CreateMediaTypeSegmentWithQuality(System.String mediaType, System.Int32 start)", + "Kind": "Removal" + }, + { + "TypeId": "public abstract class Microsoft.AspNetCore.Mvc.ModelBinding.ObjectModelValidator : Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator", + "MemberId": "public abstract Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationVisitor GetValidationVisitor(Microsoft.AspNetCore.Mvc.ActionContext actionContext, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IModelValidatorProvider validatorProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidatorCache validatorCache, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider metadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.ValidationStateDictionary validationState)", + "Kind": "Addition" } ] \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsApplicationModelProvider.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsApplicationModelProvider.cs index 352a8b4ee6..5afd4e6385 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsApplicationModelProvider.cs @@ -4,13 +4,13 @@ using System; using System.Linq; using Microsoft.AspNetCore.Cors.Infrastructure; +using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Routing; -namespace Microsoft.AspNetCore.Mvc.Cors.Internal +namespace Microsoft.AspNetCore.Mvc.Cors { - public class CorsApplicationModelProvider : IApplicationModelProvider + internal class CorsApplicationModelProvider : IApplicationModelProvider { public int Order => -1000 + 10; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs index 0d853eae9d..d4b374849d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilter.cs @@ -5,7 +5,6 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Cors.Infrastructure; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Cors.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Primitives; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsAuthorizationFilterFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilterFactory.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsAuthorizationFilterFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilterFactory.cs index 9cb7146f5c..517a85aea1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsAuthorizationFilterFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsAuthorizationFilterFactory.cs @@ -5,12 +5,12 @@ using System; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Cors.Internal +namespace Microsoft.AspNetCore.Mvc.Cors { /// /// A filter factory which creates a new instance of . /// - public class CorsAuthorizationFilterFactory : IFilterFactory, IOrderedFilter + internal class CorsAuthorizationFilterFactory : IFilterFactory, IOrderedFilter { private readonly string _policyName; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsHttpMethodActionConstraint.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsHttpMethodActionConstraint.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsHttpMethodActionConstraint.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsHttpMethodActionConstraint.cs index de3ff06468..d909180ac2 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsHttpMethodActionConstraint.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsHttpMethodActionConstraint.cs @@ -2,16 +2,14 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.Extensions.Primitives; -using Microsoft.AspNetCore.Mvc.Internal; -namespace Microsoft.AspNetCore.Mvc.Cors.Internal +namespace Microsoft.AspNetCore.Mvc.Cors { // Don't casually change the name of this. We reference the full type name in ActionConstraintCache. - public class CorsHttpMethodActionConstraint : HttpMethodActionConstraint + internal class CorsHttpMethodActionConstraint : HttpMethodActionConstraint { private readonly string OriginHeader = "Origin"; private readonly string AccessControlRequestMethod = "Access-Control-Request-Method"; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsLoggerExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsLoggerExtensions.cs similarity index 89% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsLoggerExtensions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsLoggerExtensions.cs index c3fab172b9..8bc4af91f4 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/CorsLoggerExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/CorsLoggerExtensions.cs @@ -4,9 +4,9 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Cors.Internal +namespace Microsoft.AspNetCore.Mvc.Cors { - public static class CorsLoggerExtensions + internal static class CorsLoggerExtensions { private static readonly Action _notMostEffectiveFilter; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs index a4cf5c1800..460a0cb4f9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/DependencyInjection/MvcCorsMvcCoreBuilderExtensions.cs @@ -5,7 +5,6 @@ using System; using Microsoft.AspNetCore.Cors.Infrastructure; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Cors; -using Microsoft.AspNetCore.Mvc.Cors.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/DisableCorsAuthorizationFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/DisableCorsAuthorizationFilter.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/DisableCorsAuthorizationFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/DisableCorsAuthorizationFilter.cs index 8ecd6cbfb6..183add11a9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/DisableCorsAuthorizationFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/DisableCorsAuthorizationFilter.cs @@ -8,12 +8,12 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.Cors.Internal +namespace Microsoft.AspNetCore.Mvc.Cors { /// /// An which ensures that an action does not run for a pre-flight request. /// - public class DisableCorsAuthorizationFilter : ICorsAuthorizationFilter + internal class DisableCorsAuthorizationFilter : ICorsAuthorizationFilter { /// // Since clients' preflight requests would not have data to authenticate requests, this diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/ICorsAuthorizationFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/ICorsAuthorizationFilter.cs similarity index 71% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/ICorsAuthorizationFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/ICorsAuthorizationFilter.cs index 6989ffd421..483a70980d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Internal/ICorsAuthorizationFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/ICorsAuthorizationFilter.cs @@ -3,12 +3,12 @@ using Microsoft.AspNetCore.Mvc.Filters; -namespace Microsoft.AspNetCore.Mvc.Cors.Internal +namespace Microsoft.AspNetCore.Mvc.Cors { /// /// A filter that can be used to enable/disable CORS support for a resource. /// - public interface ICorsAuthorizationFilter : IAsyncAuthorizationFilter, IOrderedFilter + internal interface ICorsAuthorizationFilter : IAsyncAuthorizationFilter, IOrderedFilter { } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Microsoft.AspNetCore.Mvc.Cors.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Microsoft.AspNetCore.Mvc.Cors.csproj index 379eca0738..59ab59c696 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Microsoft.AspNetCore.Mvc.Cors.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Microsoft.AspNetCore.Mvc.Cors.csproj @@ -2,7 +2,7 @@ ASP.NET Core MVC cross-origin resource sharing (CORS) features. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc;cors diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Properties/AssemblyInfo.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Properties/AssemblyInfo.cs index 19603aa2df..5a3d62d5ad 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Properties/AssemblyInfo.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/Properties/AssemblyInfo.cs @@ -3,4 +3,6 @@ using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Core.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Cors.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/breakingchanges.netcore.json b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/breakingchanges.netcore.json new file mode 100644 index 0000000000..6c3a2d285c --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Cors/breakingchanges.netcore.json @@ -0,0 +1,6 @@ +[ + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Cors.CorsAuthorizationFilter : Microsoft.AspNetCore.Mvc.Cors.Internal.ICorsAuthorizationFilter", + "Kind": "Removal" + } +] diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/CompareAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/CompareAttributeAdapter.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/CompareAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/CompareAttributeAdapter.cs index f64272fa04..43e60f89e5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/CompareAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/CompareAttributeAdapter.cs @@ -8,9 +8,9 @@ using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class CompareAttributeAdapter : AttributeAdapterBase + internal class CompareAttributeAdapter : AttributeAdapterBase { private readonly string _otherProperty; @@ -105,4 +105,4 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsClientModelValidatorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsClientModelValidatorProvider.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsClientModelValidatorProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsClientModelValidatorProvider.cs index 05d2aacac3..946db2b755 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsClientModelValidatorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsClientModelValidatorProvider.cs @@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { /// /// An implementation of which provides client validators @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal /// The logic to support /// is implemented in . /// - public class DataAnnotationsClientModelValidatorProvider : IClientModelValidatorProvider + internal class DataAnnotationsClientModelValidatorProvider : IClientModelValidatorProvider { private readonly IOptions _options; private readonly IStringLocalizerFactory _stringLocalizerFactory; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsLocalizationServices.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsLocalizationServices.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsLocalizationServices.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsLocalizationServices.cs index 3ef1fde707..75c6a013fc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsLocalizationServices.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsLocalizationServices.cs @@ -6,9 +6,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public static class DataAnnotationsLocalizationServices + internal static class DataAnnotationsLocalizationServices { public static void AddDataAnnotationsLocalizationServices( IServiceCollection services, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsMetadataProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsMetadataProvider.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsMetadataProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsMetadataProvider.cs index d0a2875c5a..e94ee78153 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsMetadataProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsMetadataProvider.cs @@ -12,13 +12,13 @@ using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { /// /// An implementation of and for /// the System.ComponentModel.DataAnnotations attribute classes. /// - public class DataAnnotationsMetadataProvider : + internal class DataAnnotationsMetadataProvider : IBindingMetadataProvider, IDisplayMetadataProvider, IValidationMetadataProvider @@ -388,4 +388,4 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal return string.Empty; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsModelValidator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsModelValidator.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsModelValidator.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsModelValidator.cs index 563fa078a7..b70a7c4825 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataAnnotationsModelValidator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsModelValidator.cs @@ -8,12 +8,12 @@ using System.Linq; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { /// /// Validates based on the given . /// - public class DataAnnotationsModelValidator : IModelValidator + internal class DataAnnotationsModelValidator : IModelValidator { private static readonly object _emptyValidationContextInstance = new object(); private readonly IStringLocalizer _stringLocalizer; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsModelValidatorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsModelValidatorProvider.cs index b6266958c3..a0cd1c4d68 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsModelValidatorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataAnnotationsModelValidatorProvider.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataTypeAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataTypeAttributeAdapter.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataTypeAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataTypeAttributeAdapter.cs index b9bfa16165..0c6bf4e115 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DataTypeAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DataTypeAttributeAdapter.cs @@ -6,13 +6,13 @@ using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { /// /// A validation adapter that is used to map 's to a single client side validation /// rule. /// - public class DataTypeAttributeAdapter : AttributeAdapterBase + internal class DataTypeAttributeAdapter : AttributeAdapterBase { public DataTypeAttributeAdapter(DataTypeAttribute attribute, string ruleName, IStringLocalizer stringLocalizer) : base(attribute, stringLocalizer) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DefaultClientModelValidatorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DefaultClientModelValidatorProvider.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DefaultClientModelValidatorProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DefaultClientModelValidatorProvider.cs index 2fb0fe4769..54a533a417 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/DefaultClientModelValidatorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DefaultClientModelValidatorProvider.cs @@ -4,7 +4,7 @@ using System; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { /// /// A default implementation of . @@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal /// The provides validators from /// instances in . /// - public class DefaultClientModelValidatorProvider : IClientModelValidatorProvider + internal class DefaultClientModelValidatorProvider : IClientModelValidatorProvider { /// public void CreateValidators(ClientValidatorProviderContext context) @@ -42,4 +42,4 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MvcDataAnnotationsLocalizationConfigureCompatibilityOptions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsLocalizationConfigureCompatibilityOptions.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MvcDataAnnotationsLocalizationConfigureCompatibilityOptions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsLocalizationConfigureCompatibilityOptions.cs index e3eab734b7..eb07025356 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MvcDataAnnotationsLocalizationConfigureCompatibilityOptions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsLocalizationConfigureCompatibilityOptions.cs @@ -2,11 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.DataAnnotations; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations +namespace Microsoft.Extensions.DependencyInjection { internal class MvcDataAnnotationsLocalizationConfigureCompatibilityOptions : ConfigureCompatibilityOptions { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MvcDataAnnotationsLocalizationOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsLocalizationOptionsSetup.cs similarity index 77% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MvcDataAnnotationsLocalizationOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsLocalizationOptionsSetup.cs index e91f13b255..5410042c30 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MvcDataAnnotationsLocalizationOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsLocalizationOptionsSetup.cs @@ -2,14 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Mvc.DataAnnotations; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// Sets up default options for . /// - public class MvcDataAnnotationsLocalizationOptionsSetup : IConfigureOptions + internal class MvcDataAnnotationsLocalizationOptionsSetup : IConfigureOptions { /// public void Configure(MvcDataAnnotationsLocalizationOptions options) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcBuilderExtensions.cs index ddbd623b3e..8ed3212e8b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcBuilderExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Mvc.DataAnnotations; -using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal; namespace Microsoft.Extensions.DependencyInjection { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcCoreBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcCoreBuilderExtensions.cs index 160a73345e..76a9ae46bb 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcCoreBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcCoreBuilderExtensions.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.DataAnnotations; -using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MvcDataAnnotationsMvcOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcOptionsSetup.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MvcDataAnnotationsMvcOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcOptionsSetup.cs index 1b94e5c157..f43d3cca66 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MvcDataAnnotationsMvcOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/DependencyInjection/MvcDataAnnotationsMvcOptionsSetup.cs @@ -2,15 +2,17 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.DataAnnotations; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// Sets up default options for . /// - public class MvcDataAnnotationsMvcOptionsSetup : IConfigureOptions + internal class MvcDataAnnotationsMvcOptionsSetup : IConfigureOptions { private readonly IStringLocalizerFactory _stringLocalizerFactory; private readonly IValidationAttributeAdapterProvider _validationAttributeAdapterProvider; @@ -60,4 +62,4 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal _stringLocalizerFactory)); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/FileExtensionsAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/FileExtensionsAttributeAdapter.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/FileExtensionsAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/FileExtensionsAttributeAdapter.cs index 827188f769..c7f62c67ad 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/FileExtensionsAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/FileExtensionsAttributeAdapter.cs @@ -7,9 +7,9 @@ using System.Linq; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class FileExtensionsAttributeAdapter : AttributeAdapterBase + internal class FileExtensionsAttributeAdapter : AttributeAdapterBase { private readonly string _extensions; private readonly string _formattedExtensions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MaxLengthAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MaxLengthAttributeAdapter.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MaxLengthAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MaxLengthAttributeAdapter.cs index 3a1a2cf9e9..e07e1165af 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MaxLengthAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MaxLengthAttributeAdapter.cs @@ -7,9 +7,9 @@ using System.Globalization; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class MaxLengthAttributeAdapter : AttributeAdapterBase + internal class MaxLengthAttributeAdapter : AttributeAdapterBase { private readonly string _max; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Microsoft.AspNetCore.Mvc.DataAnnotations.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Microsoft.AspNetCore.Mvc.DataAnnotations.csproj index 33df42b291..a1e363328f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Microsoft.AspNetCore.Mvc.DataAnnotations.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Microsoft.AspNetCore.Mvc.DataAnnotations.csproj @@ -2,7 +2,7 @@ ASP.NET Core MVC metadata and validation system using System.ComponentModel.DataAnnotations. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MinLengthAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MinLengthAttributeAdapter.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MinLengthAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MinLengthAttributeAdapter.cs index 8d713b823c..488e17d59b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/MinLengthAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/MinLengthAttributeAdapter.cs @@ -7,9 +7,9 @@ using System.Globalization; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class MinLengthAttributeAdapter : AttributeAdapterBase + internal class MinLengthAttributeAdapter : AttributeAdapterBase { private readonly string _min; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/NumericClientModelValidator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/NumericClientModelValidator.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/NumericClientModelValidator.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/NumericClientModelValidator.cs index edc0286909..f9fc45d470 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/NumericClientModelValidator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/NumericClientModelValidator.cs @@ -6,13 +6,13 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { /// /// An implementation of that provides the rule for validating /// numeric types. /// - public class NumericClientModelValidator : IClientModelValidator + internal class NumericClientModelValidator : IClientModelValidator { /// public void AddValidation(ClientModelValidationContext context) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/NumericClientModelValidatorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/NumericClientModelValidatorProvider.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/NumericClientModelValidatorProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/NumericClientModelValidatorProvider.cs index a2e182d381..20c1cf086a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/NumericClientModelValidatorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/NumericClientModelValidatorProvider.cs @@ -4,13 +4,13 @@ using System; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { /// /// An implementation of which provides client validators /// for specific numeric types. /// - public class NumericClientModelValidatorProvider : IClientModelValidatorProvider + internal class NumericClientModelValidatorProvider : IClientModelValidatorProvider { /// public void CreateValidators(ClientValidatorProviderContext context) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Properties/AssemblyInfo.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Properties/AssemblyInfo.cs index a0584f4754..06956dcef0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Properties/AssemblyInfo.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Properties/AssemblyInfo.cs @@ -3,10 +3,13 @@ using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.ViewFeatures, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] + [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.DataAnnotations.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Core.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Core.TestCommon, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.IntegrationTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.ViewFeatures.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RangeAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RangeAttributeAdapter.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RangeAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RangeAttributeAdapter.cs index 345e6cc3b9..692dc900d0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RangeAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RangeAttributeAdapter.cs @@ -7,9 +7,9 @@ using System.Globalization; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class RangeAttributeAdapter : AttributeAdapterBase + internal class RangeAttributeAdapter : AttributeAdapterBase { private readonly string _max; private readonly string _min; @@ -56,4 +56,4 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal Attribute.Maximum); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RegularExpressionAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RegularExpressionAttributeAdapter.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RegularExpressionAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RegularExpressionAttributeAdapter.cs index 552c5dcad2..d0278580cc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RegularExpressionAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RegularExpressionAttributeAdapter.cs @@ -6,9 +6,9 @@ using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class RegularExpressionAttributeAdapter : AttributeAdapterBase + internal class RegularExpressionAttributeAdapter : AttributeAdapterBase { public RegularExpressionAttributeAdapter(RegularExpressionAttribute attribute, IStringLocalizer stringLocalizer) : base(attribute, stringLocalizer) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RequiredAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RequiredAttributeAdapter.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RequiredAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RequiredAttributeAdapter.cs index 90e33ab49e..e4f824ae30 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/RequiredAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/RequiredAttributeAdapter.cs @@ -6,9 +6,9 @@ using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class RequiredAttributeAdapter : AttributeAdapterBase + internal class RequiredAttributeAdapter : AttributeAdapterBase { public RequiredAttributeAdapter(RequiredAttribute attribute, IStringLocalizer stringLocalizer) : base(attribute, stringLocalizer) @@ -37,4 +37,4 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal return GetErrorMessage(validationContext.ModelMetadata, validationContext.ModelMetadata.GetDisplayName()); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/StringLengthAttributeAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/StringLengthAttributeAdapter.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/StringLengthAttributeAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/StringLengthAttributeAdapter.cs index f733d4470a..e1df7efab2 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/StringLengthAttributeAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/StringLengthAttributeAdapter.cs @@ -7,9 +7,9 @@ using System.Globalization; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.Extensions.Localization; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class StringLengthAttributeAdapter : AttributeAdapterBase + internal class StringLengthAttributeAdapter : AttributeAdapterBase { private readonly string _max; private readonly string _min; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/ValidatableObjectAdapter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/ValidatableObjectAdapter.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/ValidatableObjectAdapter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/ValidatableObjectAdapter.cs index 55a9ca23a1..022e637fb8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/Internal/ValidatableObjectAdapter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/ValidatableObjectAdapter.cs @@ -7,9 +7,9 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; -namespace Microsoft.AspNetCore.Mvc.DataAnnotations.Internal +namespace Microsoft.AspNetCore.Mvc.DataAnnotations { - public class ValidatableObjectAdapter : IModelValidator + internal class ValidatableObjectAdapter : IModelValidator { public IEnumerable Validate(ModelValidationContext context) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/ValidationAttributeAdapterProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/ValidationAttributeAdapterProvider.cs index a16b405a5f..7ec543d39d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/ValidationAttributeAdapterProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.DataAnnotations/ValidationAttributeAdapterProvider.cs @@ -3,7 +3,6 @@ using System; using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal; using Microsoft.Extensions.Localization; namespace Microsoft.AspNetCore.Mvc.DataAnnotations diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonMvcCoreBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonMvcCoreBuilderExtensions.cs index accd9045eb..7314bb1df9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonMvcCoreBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonMvcCoreBuilderExtensions.cs @@ -4,8 +4,8 @@ using System; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Formatters.Json; -using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using Newtonsoft.Json; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MvcJsonMvcOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonMvcOptionsSetup.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MvcJsonMvcOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonMvcOptionsSetup.cs index 33f2b51eac..bc2f044e92 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MvcJsonMvcOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonMvcOptionsSetup.cs @@ -4,19 +4,20 @@ using System; using System.Buffers; using Microsoft.AspNetCore.JsonPatch; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.Extensions.Logging; using Microsoft.Extensions.ObjectPool; using Microsoft.Extensions.Options; -using Microsoft.Net.Http.Headers; using Newtonsoft.Json.Linq; -namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// Sets up JSON formatter options for . /// - public class MvcJsonMvcOptionsSetup : IConfigureOptions + internal class MvcJsonMvcOptionsSetup : IConfigureOptions { private readonly ILoggerFactory _loggerFactory; private readonly MvcJsonOptions _jsonOptions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonOptionsConfigureCompatibilityOptions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonOptionsConfigureCompatibilityOptions.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonOptionsConfigureCompatibilityOptions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonOptionsConfigureCompatibilityOptions.cs index f33e6dc108..5fe4836b37 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonOptionsConfigureCompatibilityOptions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonOptionsConfigureCompatibilityOptions.cs @@ -2,11 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc +namespace Microsoft.Extensions.DependencyInjection { internal class MvcJsonOptionsConfigureCompatibilityOptions : ConfigureCompatibilityOptions { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonOptionsExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonOptionsExtensions.cs similarity index 100% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonOptionsExtensions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/DependencyInjection/MvcJsonOptionsExtensions.cs diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonArrayPool.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonArrayPool.cs similarity index 88% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonArrayPool.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonArrayPool.cs index 437f9bcf98..773dc82693 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonArrayPool.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonArrayPool.cs @@ -5,9 +5,9 @@ using System; using System.Buffers; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { - public class JsonArrayPool : IArrayPool + internal class JsonArrayPool : IArrayPool { private readonly ArrayPool _inner; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs index cc21792d71..1d8cdaab45 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonInputFormatter.cs @@ -10,7 +10,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Logging; @@ -262,32 +261,48 @@ namespace Microsoft.AspNetCore.Mvc.Formatters { successful = false; - // Handle path combinations such as "" + "Property", "Parent" + "Property", or "Parent" + "[12]". - var key = eventArgs.ErrorContext.Path; - if (!string.IsNullOrEmpty(context.ModelName)) + // When ErrorContext.Path does not include ErrorContext.Member, add Member to form full path. + var path = eventArgs.ErrorContext.Path; + var member = eventArgs.ErrorContext.Member?.ToString(); + var addMember = !string.IsNullOrEmpty(member); + if (addMember) { - if (string.IsNullOrEmpty(eventArgs.ErrorContext.Path)) + // Path.Member case (path.Length < member.Length) needs no further checks. + if (path.Length == member.Length) { - key = context.ModelName; + // Add Member in Path.Memb case but not for Path.Path. + addMember = !string.Equals(path, member, StringComparison.Ordinal); } - else if (eventArgs.ErrorContext.Path[0] == '[') + else if (path.Length > member.Length) { - key = context.ModelName + eventArgs.ErrorContext.Path; - } - else - { - key = context.ModelName + "." + eventArgs.ErrorContext.Path; + // Finally, check whether Path already ends with Member. + if (member[0] == '[') + { + addMember = !path.EndsWith(member, StringComparison.Ordinal); + } + else + { + addMember = !path.EndsWith("." + member, StringComparison.Ordinal); + } } } - var metadata = GetPathMetadata(context.Metadata, eventArgs.ErrorContext.Path); - var modelStateException = WrapExceptionForModelState(eventArgs.ErrorContext.Error); - context.ModelState.TryAddModelError(key, modelStateException, metadata); + if (addMember) + { + path = ModelNames.CreatePropertyModelName(path, member); + } - _logger.JsonInputException(eventArgs.ErrorContext.Error); + // Handle path combinations such as ""+"Property", "Parent"+"Property", or "Parent"+"[12]". + var key = ModelNames.CreatePropertyModelName(context.ModelName, path); exception = eventArgs.ErrorContext.Error; + var metadata = GetPathMetadata(context.Metadata, path); + var modelStateException = WrapExceptionForModelState(exception); + context.ModelState.TryAddModelError(key, modelStateException, metadata); + + _logger.JsonInputException(exception); + // Error must always be marked as handled // Failure to do so can cause the exception to be rethrown at every recursive level and // overflow the stack for x64 CLR processes diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonOutputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonOutputFormatter.cs index 744d558680..7dafe6fe94 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonOutputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonOutputFormatter.cs @@ -7,7 +7,6 @@ using System.ComponentModel; using System.IO; using System.Text; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal; using Newtonsoft.Json; namespace Microsoft.AspNetCore.Mvc.Formatters diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchInputFormatter.cs index 96549d44d5..9fd0a364b3 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchInputFormatter.cs @@ -7,7 +7,6 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.JsonPatch; -using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.ObjectPool; using Newtonsoft.Json; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonResult.cs index a4a576a83f..5abad92bff 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonResult.cs @@ -3,7 +3,7 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Formatters.Json.Internal; +using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonResultExecutor.cs similarity index 80% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonResultExecutor.cs index 332d1bdc59..81f0f783d7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonResultExecutor.cs @@ -6,24 +6,26 @@ using System.Buffers; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { /// /// Executes a to write to the response. /// - public class JsonResultExecutor + internal class JsonResultExecutor { private static readonly string DefaultContentType = new MediaTypeHeaderValue("application/json") { Encoding = Encoding.UTF8 }.ToString(); + private readonly IHttpResponseStreamWriterFactory _writerFactory; + private readonly ILogger _logger; + private readonly MvcJsonOptions _options; private readonly IArrayPool _charPool; /// @@ -59,34 +61,19 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal throw new ArgumentNullException(nameof(charPool)); } - WriterFactory = writerFactory; - Logger = logger; - Options = options.Value; + _writerFactory = writerFactory; + _logger = logger; + _options = options.Value; _charPool = new JsonArrayPool(charPool); } - /// - /// Gets the . - /// - protected ILogger Logger { get; } - - /// - /// Gets the . - /// - protected MvcJsonOptions Options { get; } - - /// - /// Gets the . - /// - protected IHttpResponseStreamWriterFactory WriterFactory { get; } - /// /// Executes the and writes the response. /// /// The . /// The . /// A which will complete when writing has completed. - public virtual async Task ExecuteAsync(ActionContext context, JsonResult result) + public async Task ExecuteAsync(ActionContext context, JsonResult result) { if (context == null) { @@ -114,10 +101,10 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal response.StatusCode = result.StatusCode.Value; } - var serializerSettings = result.SerializerSettings ?? Options.SerializerSettings; + var serializerSettings = result.SerializerSettings ?? _options.SerializerSettings; - Logger.JsonResultExecuting(result.Value); - using (var writer = WriterFactory.CreateWriter(response.Body, resolvedContentTypeEncoding)) + _logger.JsonResultExecuting(result.Value); + using (var writer = _writerFactory.CreateWriter(response.Body, resolvedContentTypeEncoding)) { using (var jsonWriter = new JsonTextWriter(writer)) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonSerializerObjectPolicy.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonSerializerObjectPolicy.cs similarity index 88% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonSerializerObjectPolicy.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonSerializerObjectPolicy.cs index 5cd0a0e3d6..4efc81abcc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/JsonSerializerObjectPolicy.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonSerializerObjectPolicy.cs @@ -4,12 +4,12 @@ using Microsoft.Extensions.ObjectPool; using Newtonsoft.Json; -namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { /// /// for . /// - public class JsonSerializerObjectPolicy : IPooledObjectPolicy + internal class JsonSerializerObjectPolicy : IPooledObjectPolicy { private readonly JsonSerializerSettings _serializerSettings; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MediaTypeHeaderValues.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MediaTypeHeaderValues.cs similarity index 89% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MediaTypeHeaderValues.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MediaTypeHeaderValues.cs index d9fb986507..ec791b15ef 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MediaTypeHeaderValues.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MediaTypeHeaderValues.cs @@ -3,9 +3,9 @@ using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { - internal class MediaTypeHeaderValues + internal static class MediaTypeHeaderValues { public static readonly MediaTypeHeaderValue ApplicationJson = MediaTypeHeaderValue.Parse("application/json").CopyAsReadOnly(); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Microsoft.AspNetCore.Mvc.Formatters.Json.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Microsoft.AspNetCore.Mvc.Formatters.Json.csproj index 45749b70ec..18fc52f7c7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Microsoft.AspNetCore.Mvc.Formatters.Json.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Microsoft.AspNetCore.Mvc.Formatters.Json.csproj @@ -2,7 +2,7 @@ ASP.NET Core MVC formatters for JSON input and output and for JSON PATCH input using Json.NET. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc;json diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MvcJsonLoggerExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonLoggerExtensions.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MvcJsonLoggerExtensions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonLoggerExtensions.cs index c06d819865..c4f15f190a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Internal/MvcJsonLoggerExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/MvcJsonLoggerExtensions.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters { internal static class MvcJsonLoggerExtensions { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Properties/AssemblyInfo.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Properties/AssemblyInfo.cs index 7982959233..a6552b389c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Properties/AssemblyInfo.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Json/Properties/AssemblyInfo.cs @@ -3,4 +3,6 @@ using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Formatters.Json.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.IntegrationTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/MvcXmlOptionsConfigureCompatibilityOptions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/MvcXmlOptionsConfigureCompatibilityOptions.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/MvcXmlOptionsConfigureCompatibilityOptions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/MvcXmlOptionsConfigureCompatibilityOptions.cs index c5d1d3e340..d37e67d3e1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/MvcXmlOptionsConfigureCompatibilityOptions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/MvcXmlOptionsConfigureCompatibilityOptions.cs @@ -2,12 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc +namespace Microsoft.Extensions.DependencyInjection { internal sealed class MvcXmlOptionsConfigureCompatibilityOptions : ConfigureCompatibilityOptions { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerMvcOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/XmlDataContractSerializerMvcOptionsSetup.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerMvcOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/XmlDataContractSerializerMvcOptionsSetup.cs index eba6b9d5fd..83a8fd5b67 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerMvcOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/XmlDataContractSerializerMvcOptionsSetup.cs @@ -2,15 +2,15 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Xml; -using System.Xml.Linq; -using Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml +namespace Microsoft.Extensions.DependencyInjection { /// /// A implementation which will add the diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerMvcOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/XmlSerializerMvcOptionsSetup.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerMvcOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/XmlSerializerMvcOptionsSetup.cs index 1a57d167ce..3186fab390 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerMvcOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/DependencyInjection/XmlSerializerMvcOptionsSetup.cs @@ -2,11 +2,13 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Formatters; +using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml +namespace Microsoft.Extensions.DependencyInjection { /// /// A implementation which will add the diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Internal/FormattingUtilities.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/FormattingUtilities.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Internal/FormattingUtilities.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/FormattingUtilities.cs index 7b97d7ca79..70a9c94453 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Internal/FormattingUtilities.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/FormattingUtilities.cs @@ -4,12 +4,12 @@ using System.Runtime.Serialization; using System.Xml; -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters.Xml { /// /// Contains methods which are used by Xml input formatters. /// - public static class FormattingUtilities + internal static class FormattingUtilities { public static readonly int DefaultMaxDepth = 32; public static readonly XsdDataContractExporter XsdDataContractExporter = new XsdDataContractExporter(); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/LoggerExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/LoggerExtensions.cs index dfb00627d4..76496bea3a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/LoggerExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/LoggerExtensions.cs @@ -4,9 +4,9 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters.Xml { - public static class LoggerExtensions + internal static class LoggerExtensions { private static readonly Action _failedToCreateXmlSerializer; private static readonly Action _failedToCreateDataContractSerializer; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Internal/MediaTypeHeaderValues.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/MediaTypeHeaderValues.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Internal/MediaTypeHeaderValues.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/MediaTypeHeaderValues.cs index 14f2a99ce4..24ddce0b3f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Internal/MediaTypeHeaderValues.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/MediaTypeHeaderValues.cs @@ -3,7 +3,7 @@ using Microsoft.Net.Http.Headers; -namespace Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal +namespace Microsoft.AspNetCore.Mvc.Formatters.Xml { internal static class MediaTypeHeaderValues { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Microsoft.AspNetCore.Mvc.Formatters.Xml.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Microsoft.AspNetCore.Mvc.Formatters.Xml.csproj index 18dcb55e3a..62409ab4fb 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Microsoft.AspNetCore.Mvc.Formatters.Xml.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/Microsoft.AspNetCore.Mvc.Formatters.Xml.csproj @@ -2,7 +2,7 @@ ASP.NET Core MVC formatters for XML input and output using DataContractSerializer and XmlSerializer. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc;xml diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs index f0954c36a4..ac1b2a085e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerInputFormatter.cs @@ -13,8 +13,7 @@ using System.Threading.Tasks; using System.Xml; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Formatters.Xml; -using Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.WebUtilities; namespace Microsoft.AspNetCore.Mvc.Formatters diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs index 9b89042636..c0a9cdab2d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlDataContractSerializerOutputFormatter.cs @@ -10,7 +10,6 @@ using System.Text; using System.Threading.Tasks; using System.Xml; using Microsoft.AspNetCore.Mvc.Formatters.Xml; -using Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Formatters diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs index 4d530a015b..729d9e1117 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerInputFormatter.cs @@ -13,8 +13,7 @@ using System.Xml; using System.Xml.Serialization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Formatters.Xml; -using Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.WebUtilities; namespace Microsoft.AspNetCore.Mvc.Formatters diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs index c289972ea4..9960eedbd6 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Formatters.Xml/XmlSerializerOutputFormatter.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using System.Xml; using System.Xml.Serialization; using Microsoft.AspNetCore.Mvc.Formatters.Xml; -using Microsoft.AspNetCore.Mvc.Formatters.Xml.Internal; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Formatters diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Localization/Microsoft.AspNetCore.Mvc.Localization.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Localization/Microsoft.AspNetCore.Mvc.Localization.csproj index a20bb199aa..f0a687e90c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Localization/Microsoft.AspNetCore.Mvc.Localization.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Localization/Microsoft.AspNetCore.Mvc.Localization.csproj @@ -5,7 +5,7 @@ Commonly used types: Microsoft.AspNetCore.Mvc.Localization.IHtmlLocalizer<TResource> Microsoft.AspNetCore.Mvc.Localization.IViewLocalizer - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc;localization diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompilationFailedException.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompilationFailedException.cs deleted file mode 100644 index 5e3899c0bb..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompilationFailedException.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Diagnostics; - -namespace Microsoft.AspNetCore.Mvc.Razor.Compilation -{ - /// - /// An thrown when accessing the result of a failed compilation. - /// - public class CompilationFailedException : Exception, ICompilationException - { - /// - /// Instantiates a new instance of . - /// - /// s containing - /// details of the compilation failure. - public CompilationFailedException( - IEnumerable compilationFailures) - : base(FormatMessage(compilationFailures)) - { - if (compilationFailures == null) - { - throw new ArgumentNullException(nameof(compilationFailures)); - } - - CompilationFailures = compilationFailures; - } - - /// - public IEnumerable CompilationFailures { get; } - - private static string FormatMessage(IEnumerable compilationFailures) - { - return Resources.CompilationFailed + Environment.NewLine + - string.Join( - Environment.NewLine, - compilationFailures.SelectMany(f => f.Messages).Select(message => message.FormattedMessage)); - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs index 4b4c1ec3e8..213218c5cd 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/CompiledViewDescriptor.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Razor.Hosting; using Microsoft.Extensions.Primitives; @@ -52,7 +51,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation // later. ExpirationTokens = Array.Empty(); RelativePath = ViewPath.NormalizePath(item?.Identifier ?? attribute.Path); - IsPrecompiled = true; } /// @@ -73,11 +71,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation /// public IList ExpirationTokens { get; set; } - /// - /// Gets a value that determines if the view is precompiled. - /// - public bool IsPrecompiled { get; set; } - /// /// Gets the descriptor for this view. /// diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorPageFactoryProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/DefaultRazorPageFactoryProvider.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorPageFactoryProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/DefaultRazorPageFactoryProvider.cs index b5c7341830..fc0d03cf0d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorPageFactoryProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/DefaultRazorPageFactoryProvider.cs @@ -4,15 +4,14 @@ using System; using System.Linq.Expressions; using System.Reflection; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor.Compilation { /// /// Represents a that creates instances /// from razor files in the file system. /// - public class DefaultRazorPageFactoryProvider : IRazorPageFactoryProvider + internal class DefaultRazorPageFactoryProvider : IRazorPageFactoryProvider { private readonly IViewCompilerProvider _viewCompilerProvider; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/IViewCompilationMemoryCacheProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/IViewCompilationMemoryCacheProvider.cs deleted file mode 100644 index 5abbd550f3..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/IViewCompilationMemoryCacheProvider.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Caching.Memory; - -namespace Microsoft.AspNetCore.Mvc.Razor.Compilation -{ - /// - /// Provides an instance of that is used to store compiled Razor views. - /// - public interface IViewCompilationMemoryCacheProvider - { - IMemoryCache CompilationMemoryCache { get; } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/MetadataReferenceFeature.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/MetadataReferenceFeature.cs deleted file mode 100644 index 478d21eed8..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/MetadataReferenceFeature.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using Microsoft.CodeAnalysis; - -namespace Microsoft.AspNetCore.Mvc.Razor.Compilation -{ - /// - /// Specifies the list of used in Razor compilation. - /// - [Obsolete("This type is obsolete and will be removed in a future version. See https://aka.ms/AA1x4gg for details.")] - public class MetadataReferenceFeature - { - /// - /// Gets the instances. - /// - public IList MetadataReferences { get; } = new List(); - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/MetadataReferenceFeatureProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/MetadataReferenceFeatureProvider.cs deleted file mode 100644 index 8050671a1f..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/MetadataReferenceFeatureProvider.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection.PortableExecutable; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.CodeAnalysis; -using Microsoft.Extensions.DependencyModel; - -namespace Microsoft.AspNetCore.Mvc.Razor.Compilation -{ - /// - /// An for that - /// uses for registered instances to create - /// . - /// - [Obsolete("This type is obsolete and will be removed in a future version. See https://aka.ms/AA1x4gg for details.")] - public class MetadataReferenceFeatureProvider : IApplicationFeatureProvider - { - /// - public void PopulateFeature(IEnumerable parts, MetadataReferenceFeature feature) - { - if (parts == null) - { - throw new ArgumentNullException(nameof(parts)); - } - - if (feature == null) - { - throw new ArgumentNullException(nameof(feature)); - } - - var libraryPaths = new HashSet(StringComparer.OrdinalIgnoreCase); - foreach (var providerPart in parts.OfType()) - { - var referencePaths = providerPart.GetReferencePaths(); - foreach (var path in referencePaths) - { - if (libraryPaths.Add(path)) - { - var metadataReference = CreateMetadataReference(path); - feature.MetadataReferences.Add(metadataReference); - } - } - } - } - - private static MetadataReference CreateMetadataReference(string path) - { - using (var stream = File.OpenRead(path)) - { - var moduleMetadata = ModuleMetadata.CreateFromStream(stream, PEStreamOptions.PrefetchMetadata); - var assemblyMetadata = AssemblyMetadata.Create(moduleMetadata); - - return assemblyMetadata.GetReference(filePath: path); - } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorReferenceManager.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorReferenceManager.cs deleted file mode 100644 index df09623169..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorReferenceManager.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using Microsoft.CodeAnalysis; - -namespace Microsoft.AspNetCore.Mvc.Razor.Compilation -{ - /// - /// Manages compilation references for Razor compilation. - /// - [Obsolete("This type is obsolete and will be removed in a future version. See https://aka.ms/AA1x4gg for details.")] - public abstract class RazorReferenceManager - { - /// - /// Gets the set of compilation references to be used for Razor compilation. - /// - public abstract IReadOnlyList CompilationReferences { get; } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompilationMemoryCacheProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompilationMemoryCacheProvider.cs deleted file mode 100644 index 9a11db0b3f..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompilationMemoryCacheProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Caching.Memory; - -namespace Microsoft.AspNetCore.Mvc.Razor.Compilation -{ - internal class RazorViewCompilationMemoryCacheProvider : IViewCompilationMemoryCacheProvider - { - IMemoryCache IViewCompilationMemoryCacheProvider.CompilationMemoryCache { get; } = new MemoryCache(new MemoryCacheOptions()); - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompiler.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompiler.cs new file mode 100644 index 0000000000..7afc53edab --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompiler.cs @@ -0,0 +1,115 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Primitives; + +namespace Microsoft.AspNetCore.Mvc.Razor.Compilation +{ + /// + /// Caches the result of runtime compilation of Razor files for the duration of the application lifetime. + /// + internal class RazorViewCompiler : IViewCompiler + { + private readonly Dictionary> _compiledViews; + private readonly ConcurrentDictionary _normalizedPathCache; + private readonly ILogger _logger; + + public RazorViewCompiler( + IList compiledViews, + ILogger logger) + { + if (compiledViews == null) + { + throw new ArgumentNullException(nameof(compiledViews)); + } + + if (logger == null) + { + throw new ArgumentNullException(nameof(logger)); + } + + _logger = logger; + _normalizedPathCache = new ConcurrentDictionary(StringComparer.Ordinal); + + // We need to validate that the all of the precompiled views are unique by path (case-insensitive). + // We do this because there's no good way to canonicalize paths on windows, and it will create + // problems when deploying to linux. Rather than deal with these issues, we just don't support + // views that differ only by case. + _compiledViews = new Dictionary>( + compiledViews.Count, + StringComparer.OrdinalIgnoreCase); + + foreach (var compiledView in compiledViews) + { + logger.ViewCompilerLocatedCompiledView(compiledView.RelativePath); + + if (!_compiledViews.ContainsKey(compiledView.RelativePath)) + { + // View ordering has precedence semantics, a view with a higher precedence was not + // already added to the list. + _compiledViews.Add(compiledView.RelativePath, Task.FromResult(compiledView)); + } + } + + if (_compiledViews.Count == 0) + { + logger.ViewCompilerNoCompiledViewsFound(); + } + } + + /// + public Task CompileAsync(string relativePath) + { + if (relativePath == null) + { + throw new ArgumentNullException(nameof(relativePath)); + } + + // Attempt to lookup the cache entry using the passed in path. This will succeed if the path is already + // normalized and a cache entry exists. + if (_compiledViews.TryGetValue(relativePath, out var cachedResult)) + { + _logger.ViewCompilerLocatedCompiledViewForPath(relativePath); + return cachedResult; + } + + var normalizedPath = GetNormalizedPath(relativePath); + if (_compiledViews.TryGetValue(normalizedPath, out cachedResult)) + { + _logger.ViewCompilerLocatedCompiledViewForPath(normalizedPath); + return cachedResult; + } + + // Entry does not exist. Attempt to create one. + _logger.ViewCompilerCouldNotFindFileAtPath(relativePath); + return Task.FromResult(new CompiledViewDescriptor + { + RelativePath = normalizedPath, + ExpirationTokens = Array.Empty(), + }); + } + + private string GetNormalizedPath(string relativePath) + { + Debug.Assert(relativePath != null); + if (relativePath.Length == 0) + { + return relativePath; + } + + if (!_normalizedPathCache.TryGetValue(relativePath, out var normalizedPath)) + { + normalizedPath = ViewPath.NormalizePath(relativePath); + _normalizedPathCache[relativePath] = normalizedPath; + } + + return normalizedPath; + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompilerProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompilerProvider.cs new file mode 100644 index 0000000000..64965e6f72 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RazorViewCompilerProvider.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.Extensions.Logging; + +namespace Microsoft.AspNetCore.Mvc.Razor.Compilation +{ + internal class RazorViewCompilerProvider : IViewCompilerProvider + { + private readonly RazorViewCompiler _compiler; + + public RazorViewCompilerProvider( + ApplicationPartManager applicationPartManager, + ILoggerFactory loggerFactory) + { + var feature = new ViewsFeature(); + applicationPartManager.PopulateFeature(feature); + + _compiler = new RazorViewCompiler(feature.ViewDescriptors, loggerFactory.CreateLogger()); + } + + public IViewCompiler GetCompiler() => _compiler; + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RoslynCompilationContext.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RoslynCompilationContext.cs deleted file mode 100644 index 5536969721..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/RoslynCompilationContext.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.CodeAnalysis.CSharp; - -namespace Microsoft.AspNetCore.Mvc.Razor.Compilation -{ - /// - /// Context object used to pass information about the current Razor page compilation. - /// - public class RoslynCompilationContext - { - /// - /// Constructs a new instance of the type. - /// - /// to be set to property. - public RoslynCompilationContext(CSharpCompilation compilation) - { - if (compilation == null) - { - throw new ArgumentNullException(nameof(compilation)); - } - - Compilation = compilation; - } - - /// - /// Gets or sets the used for current source file compilation. - /// - public CSharpCompilation Compilation { get; set; } - } -} \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs index e7e7143fbb..911b010261 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Compilation/ViewsFeatureProvider.cs @@ -7,7 +7,6 @@ using System.IO; using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Mvc.Razor.Compilation @@ -51,7 +50,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Compilation ExpirationTokens = Array.Empty(), RelativePath = relativePath, ViewAttribute = attribute, - IsPrecompiled = true, }; feature.ViewDescriptors.Add(viewDescriptor); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultTagHelperFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DefaultTagHelperFactory.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultTagHelperFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DefaultTagHelperFactory.cs index 6dd51965c3..f394d34581 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultTagHelperFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DefaultTagHelperFactory.cs @@ -11,12 +11,12 @@ using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { /// /// Default implementation for . /// - public class DefaultTagHelperFactory : ITagHelperFactory + internal class DefaultTagHelperFactory : ITagHelperFactory { private readonly ITagHelperActivator _activator; private readonly ConcurrentDictionary[]> _injectActions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcBuilderExtensions.cs index 8b47c02345..7fa8e4b3ae 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcBuilderExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNetCore.Mvc.Razor; -using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Razor.TagHelpers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs index 131bc13391..46139a28a0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs @@ -2,27 +2,19 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.Linq; -using System.Text.Encodings.Web; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Mvc.Razor.Infrastructure; -using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Razor.TagHelpers; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using CompilationTagHelperFeature = Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature; -using DefaultTagHelperDescriptorProvider = Microsoft.CodeAnalysis.Razor.DefaultTagHelperDescriptorProvider; namespace Microsoft.Extensions.DependencyInjection { @@ -67,13 +59,6 @@ namespace Microsoft.Extensions.DependencyInjection private static void AddRazorViewEngineFeatureProviders(IMvcCoreBuilder builder) { -#pragma warning disable CS0618 // Type or member is obsolete - if (!builder.PartManager.FeatureProviders.OfType().Any()) - { - builder.PartManager.FeatureProviders.Add(new MetadataReferenceFeatureProvider()); - } -#pragma warning restore CS0618 // Type or member is obsolete - if (!builder.PartManager.FeatureProviders.OfType().Any()) { builder.PartManager.FeatureProviders.Add(new TagHelperFeatureProvider()); @@ -149,74 +134,19 @@ namespace Microsoft.Extensions.DependencyInjection // Internal for testing. internal static void AddRazorViewEngineServices(IServiceCollection services) { - services.TryAddSingleton(); -#pragma warning disable CS0618 // Type or member is obsolete - services.TryAddSingleton(); -#pragma warning restore CS0618 // Type or member is obsolete - services.TryAddEnumerable( ServiceDescriptor.Transient, MvcRazorMvcViewOptionsSetup>()); services.TryAddEnumerable( ServiceDescriptor.Transient, RazorViewEngineOptionsSetup>()); - services.TryAddEnumerable( - ServiceDescriptor.Transient, RazorViewEngineOptionsSetup>()); - - services.TryAddSingleton< - IRazorViewEngineFileProviderAccessor, - DefaultRazorViewEngineFileProviderAccessor>(); - - services.TryAddSingleton(s => - { - var pageFactory = s.GetRequiredService(); - var pageActivator = s.GetRequiredService(); - var htmlEncoder = s.GetRequiredService(); - var optionsAccessor = s.GetRequiredService>(); - var razorFileSystem = s.GetRequiredService(); - var loggerFactory = s.GetRequiredService(); - var diagnosticSource = s.GetRequiredService(); - - var viewEngine = new RazorViewEngine(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorFileSystem, loggerFactory, diagnosticSource); - return viewEngine; - }); + services.TryAddSingleton(); services.TryAddSingleton(); - services.TryAddSingleton(); // In the default scenario the following services are singleton by virtue of being initialized as part of // creating the singleton RazorViewEngine instance. services.TryAddTransient(); - // - // Razor compilation infrastructure - // - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(s => - { - var fileSystem = s.GetRequiredService(); - var projectEngine = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem, builder => - { - RazorExtensions.Register(builder); - - // Roslyn + TagHelpers infrastructure - var metadataReferenceFeature = s.GetRequiredService(); - builder.Features.Add(metadataReferenceFeature); - builder.Features.Add(new CompilationTagHelperFeature()); - - // TagHelperDescriptorProviders (actually do tag helper discovery) - builder.Features.Add(new DefaultTagHelperDescriptorProvider()); - builder.Features.Add(new ViewComponentTagHelperDescriptorProvider()); - }); - - return projectEngine; - }); - - // Legacy Razor compilation services - services.TryAddSingleton(s => s.GetRequiredService().FileSystem); - services.TryAddSingleton(); - services.TryAddSingleton(s => s.GetRequiredService().Engine); - // This caches Razor page activation details that are valid for the lifetime of the application. services.TryAddSingleton(); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorMvcViewOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcViewOptionsSetup.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorMvcViewOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcViewOptionsSetup.cs index 8b35da8ddf..f932560411 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorMvcViewOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcViewOptionsSetup.cs @@ -2,14 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.Extensions.DependencyInjection { /// /// Configures to use . /// - public class MvcRazorMvcViewOptionsSetup : IConfigureOptions + internal class MvcRazorMvcViewOptionsSetup : IConfigureOptions { private readonly IRazorViewEngine _razorViewEngine; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelpersAsServices.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/TagHelpersAsServices.cs similarity index 88% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelpersAsServices.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/TagHelpersAsServices.cs index a441c75de1..7ef080696b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelpersAsServices.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/TagHelpersAsServices.cs @@ -4,13 +4,13 @@ using System; using System.Linq; using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Razor.TagHelpers; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.Extensions.DependencyInjection { - public static class TagHelpersAsServices + internal static class TagHelpersAsServices { public static void AddTagHelpersAsServices(ApplicationPartManager manager, IServiceCollection services) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultTagHelperActivator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Infrastructure/DefaultTagHelperActivator.cs similarity index 89% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultTagHelperActivator.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Infrastructure/DefaultTagHelperActivator.cs index c52a77a2eb..8146ca0758 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultTagHelperActivator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Infrastructure/DefaultTagHelperActivator.cs @@ -2,16 +2,16 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Razor.TagHelpers; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor.Infrastructure { /// /// Default implementation of . /// - public class DefaultTagHelperActivator : ITagHelperActivator + internal class DefaultTagHelperActivator : ITagHelperActivator { private readonly ITypeActivatorCache _typeActivatorCache; @@ -43,4 +43,4 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal typeof(TTagHelper)); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs deleted file mode 100644 index 496d2f9ee7..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CSharpCompiler.cs +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Emit; -using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.DependencyModel; -using DependencyContextCompilationOptions = Microsoft.Extensions.DependencyModel.CompilationOptions; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public class CSharpCompiler - { -#pragma warning disable CS0618 // Type or member is obsolete - private readonly RazorReferenceManager _referenceManager; -#pragma warning restore CS0618 // Type or member is obsolete - private readonly IHostingEnvironment _hostingEnvironment; - private bool _optionsInitialized; - private CSharpParseOptions _parseOptions; - private CSharpCompilationOptions _compilationOptions; - private EmitOptions _emitOptions; - private bool _emitPdb; - -#pragma warning disable CS0618 // Type or member is obsolete - public CSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment) -#pragma warning restore CS0618 // Type or member is obsolete - { - _referenceManager = manager ?? throw new ArgumentNullException(nameof(manager)); - _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); - } - - public virtual CSharpParseOptions ParseOptions - { - get - { - EnsureOptions(); - return _parseOptions; - } - } - - public virtual CSharpCompilationOptions CSharpCompilationOptions - { - get - { - EnsureOptions(); - return _compilationOptions; - } - } - - public virtual bool EmitPdb - { - get - { - EnsureOptions(); - return _emitPdb; - } - } - - public virtual EmitOptions EmitOptions - { - get - { - EnsureOptions(); - return _emitOptions; - } - } - - public SyntaxTree CreateSyntaxTree(SourceText sourceText) - { - return CSharpSyntaxTree.ParseText( - sourceText, - options: ParseOptions); - } - - public CSharpCompilation CreateCompilation(string assemblyName) - { - return CSharpCompilation.Create( - assemblyName, - options: CSharpCompilationOptions, - references: _referenceManager.CompilationReferences); - } - - // Internal for unit testing. - protected internal virtual DependencyContextCompilationOptions GetDependencyContextCompilationOptions() - { - if (!string.IsNullOrEmpty(_hostingEnvironment.ApplicationName)) - { - var applicationAssembly = Assembly.Load(new AssemblyName(_hostingEnvironment.ApplicationName)); - var dependencyContext = DependencyContext.Load(applicationAssembly); - if (dependencyContext?.CompilationOptions != null) - { - return dependencyContext.CompilationOptions; - } - } - - return DependencyContextCompilationOptions.Default; - } - - private void EnsureOptions() - { - if (!_optionsInitialized) - { - var dependencyContextOptions = GetDependencyContextCompilationOptions(); - _parseOptions = GetParseOptions(_hostingEnvironment, dependencyContextOptions); - _compilationOptions = GetCompilationOptions(_hostingEnvironment, dependencyContextOptions); - _emitOptions = GetEmitOptions(dependencyContextOptions); - - _optionsInitialized = true; - } - } - - private EmitOptions GetEmitOptions(DependencyContextCompilationOptions dependencyContextOptions) - { - // Assume we're always producing pdbs unless DebugType = none - _emitPdb = true; - DebugInformationFormat debugInformationFormat; - if (string.IsNullOrEmpty(dependencyContextOptions.DebugType)) - { - debugInformationFormat = SymbolsUtility.SupportsFullPdbGeneration() ? - DebugInformationFormat.Pdb : - DebugInformationFormat.PortablePdb; - } - else - { - // Based on https://github.com/dotnet/roslyn/blob/1d28ff9ba248b332de3c84d23194a1d7bde07e4d/src/Compilers/CSharp/Portable/CommandLine/CSharpCommandLineParser.cs#L624-L640 - switch (dependencyContextOptions.DebugType.ToLower()) - { - case "none": - // There isn't a way to represent none in DebugInformationFormat. - // We'll set EmitPdb to false and let callers handle it by setting a null pdb-stream. - _emitPdb = false; - return new EmitOptions(); - case "portable": - debugInformationFormat = DebugInformationFormat.PortablePdb; - break; - case "embedded": - // Roslyn does not expose enough public APIs to produce a binary with embedded pdbs. - // We'll produce PortablePdb instead to continue providing a reasonable user experience. - debugInformationFormat = DebugInformationFormat.PortablePdb; - break; - case "full": - case "pdbonly": - debugInformationFormat = SymbolsUtility.SupportsFullPdbGeneration() ? - DebugInformationFormat.Pdb : - DebugInformationFormat.PortablePdb; - break; - default: - throw new InvalidOperationException(Resources.FormatUnsupportedDebugInformationFormat(dependencyContextOptions.DebugType)); - } - } - - var emitOptions = new EmitOptions(debugInformationFormat: debugInformationFormat); - return emitOptions; - } - - private static CSharpCompilationOptions GetCompilationOptions( - IHostingEnvironment hostingEnvironment, - DependencyContextCompilationOptions dependencyContextOptions) - { - var csharpCompilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); - - // Disable 1702 until roslyn turns this off by default - csharpCompilationOptions = csharpCompilationOptions.WithSpecificDiagnosticOptions( - new Dictionary - { - {"CS1701", ReportDiagnostic.Suppress}, // Binding redirects - {"CS1702", ReportDiagnostic.Suppress}, - {"CS1705", ReportDiagnostic.Suppress} - }); - - if (dependencyContextOptions.AllowUnsafe.HasValue) - { - csharpCompilationOptions = csharpCompilationOptions.WithAllowUnsafe( - dependencyContextOptions.AllowUnsafe.Value); - } - - OptimizationLevel optimizationLevel; - if (dependencyContextOptions.Optimize.HasValue) - { - optimizationLevel = dependencyContextOptions.Optimize.Value ? - OptimizationLevel.Release : - OptimizationLevel.Debug; - } - else - { - optimizationLevel = hostingEnvironment.IsDevelopment() ? - OptimizationLevel.Debug : - OptimizationLevel.Release; - } - csharpCompilationOptions = csharpCompilationOptions.WithOptimizationLevel(optimizationLevel); - - if (dependencyContextOptions.WarningsAsErrors.HasValue) - { - var reportDiagnostic = dependencyContextOptions.WarningsAsErrors.Value ? - ReportDiagnostic.Error : - ReportDiagnostic.Default; - csharpCompilationOptions = csharpCompilationOptions.WithGeneralDiagnosticOption(reportDiagnostic); - } - - return csharpCompilationOptions; - } - - private static CSharpParseOptions GetParseOptions( - IHostingEnvironment hostingEnvironment, - DependencyContextCompilationOptions dependencyContextOptions) - { - var configurationSymbol = hostingEnvironment.IsDevelopment() ? "DEBUG" : "RELEASE"; - var defines = dependencyContextOptions.Defines.Concat(new[] { configurationSymbol }); - - var parseOptions = new CSharpParseOptions(preprocessorSymbols: defines); - - if (!string.IsNullOrEmpty(dependencyContextOptions.LanguageVersion)) - { - if (LanguageVersionFacts.TryParse(dependencyContextOptions.LanguageVersion, out var languageVersion)) - { - parseOptions = parseOptions.WithLanguageVersion(languageVersion); - } - else - { - Debug.Fail($"LanguageVersion {languageVersion} specified in the deps file could not be parsed."); - } - } - - return parseOptions; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ChecksumValidator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ChecksumValidator.cs deleted file mode 100644 index fea6a7ba2d..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ChecksumValidator.cs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using Microsoft.AspNetCore.Razor.Hosting; -using Microsoft.AspNetCore.Razor.Language; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public static class ChecksumValidator - { - public static bool IsRecompilationSupported(RazorCompiledItem item) - { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - // A Razor item only supports recompilation if its primary source file has a checksum. - // - // Other files (view imports) may or may not have existed at the time of compilation, - // so we may not have checksums for them. - var checksums = item.GetChecksumMetadata(); - return checksums.Any(c => string.Equals(item.Identifier, c.Identifier, StringComparison.OrdinalIgnoreCase)); - } - - // Validates that we can use an existing precompiled view by comparing checksums with files on - // disk. - public static bool IsItemValid(RazorProjectFileSystem fileSystem, RazorCompiledItem item) - { - if (fileSystem == null) - { - throw new ArgumentNullException(nameof(fileSystem)); - } - - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } - - var checksums = item.GetChecksumMetadata(); - - // The checksum that matches 'Item.Identity' in this list is significant. That represents the main file. - // - // We don't really care about the validation unless the main file exists. This is because we expect - // most sites to have some _ViewImports in common location. That means that in the case you're - // using views from a 3rd party library, you'll always have **some** conflicts. - // - // The presence of the main file with the same content is a very strong signal that you're in a - // development scenario. - var primaryChecksum = checksums - .FirstOrDefault(c => string.Equals(item.Identifier, c.Identifier, StringComparison.OrdinalIgnoreCase)); - if (primaryChecksum == null) - { - // No primary checksum, assume valid. - return true; - } - - var projectItem = fileSystem.GetItem(primaryChecksum.Identifier); - if (!projectItem.Exists) - { - // Main file doesn't exist - assume valid. - return true; - } - - var sourceDocument = RazorSourceDocument.ReadFrom(projectItem); - if (!string.Equals(sourceDocument.GetChecksumAlgorithm(), primaryChecksum.ChecksumAlgorithm) || - !ChecksumsEqual(primaryChecksum.Checksum, sourceDocument.GetChecksum())) - { - // Main file exists, but checksums not equal. - return false; - } - - for (var i = 0; i < checksums.Count; i++) - { - var checksum = checksums[i]; - if (string.Equals(item.Identifier, checksum.Identifier, StringComparison.OrdinalIgnoreCase)) - { - // Ignore primary checksum on this pass. - continue; - } - - var importItem = fileSystem.GetItem(checksum.Identifier); - if (!importItem.Exists) - { - // Import file doesn't exist - assume invalid. - return false; - } - - sourceDocument = RazorSourceDocument.ReadFrom(importItem); - if (!string.Equals(sourceDocument.GetChecksumAlgorithm(), checksum.ChecksumAlgorithm) || - !ChecksumsEqual(checksum.Checksum, sourceDocument.GetChecksum())) - { - // Import file exists, but checksums not equal. - return false; - } - } - - return true; - } - - private static bool ChecksumsEqual(string checksum, byte[] bytes) - { - if (bytes.Length * 2 != checksum.Length) - { - return false; - } - - for (var i = 0; i < bytes.Length; i++) - { - var text = bytes[i].ToString("x2"); - if (checksum[i * 2] != text[0] || checksum[i * 2 + 1] != text[1]) - { - return false; - } - } - - return true; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CompilationFailedExceptionFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CompilationFailedExceptionFactory.cs deleted file mode 100644 index 02b096ec75..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/CompilationFailedExceptionFactory.cs +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.AspNetCore.Diagnostics; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - internal static class CompilationFailedExceptionFactory - { - // error CS0234: The type or namespace name 'C' does not exist in the namespace 'N' (are you missing - // an assembly reference?) - private const string CS0234 = nameof(CS0234); - // error CS0246: The type or namespace name 'T' could not be found (are you missing a using directive - // or an assembly reference?) - private const string CS0246 = nameof(CS0246); - - public static CompilationFailedException Create( - RazorCodeDocument codeDocument, - IEnumerable diagnostics) - { - // If a SourceLocation does not specify a file path, assume it is produced from parsing the current file. - var messageGroups = diagnostics.GroupBy( - razorError => razorError.Span.FilePath ?? codeDocument.Source.FilePath, - StringComparer.Ordinal); - - var failures = new List(); - foreach (var group in messageGroups) - { - var filePath = group.Key; - var fileContent = ReadContent(codeDocument, filePath); - var compilationFailure = new CompilationFailure( - filePath, - fileContent, - compiledContent: string.Empty, - messages: group.Select(parserError => CreateDiagnosticMessage(parserError, filePath))); - failures.Add(compilationFailure); - } - - return new CompilationFailedException(failures); - } - - public static CompilationFailedException Create( - RazorCodeDocument codeDocument, - string compilationContent, - string assemblyName, - IEnumerable diagnostics) - { - var diagnosticGroups = diagnostics - .Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error) - .GroupBy(diagnostic => GetFilePath(codeDocument, diagnostic), StringComparer.Ordinal); - - var failures = new List(); - foreach (var group in diagnosticGroups) - { - var sourceFilePath = group.Key; - string sourceFileContent; - if (string.Equals(assemblyName, sourceFilePath, StringComparison.Ordinal)) - { - // The error is in the generated code and does not have a mapping line pragma - sourceFileContent = compilationContent; - sourceFilePath = Resources.GeneratedCodeFileName; - } - else - { - sourceFileContent = ReadContent(codeDocument, sourceFilePath); - } - - string additionalMessage = null; - if (group.Any(g => - string.Equals(CS0234, g.Id, StringComparison.OrdinalIgnoreCase) || - string.Equals(CS0246, g.Id, StringComparison.OrdinalIgnoreCase))) - { - additionalMessage = Resources.FormatCompilation_MissingReferences( - "CopyRefAssembliesToPublishDirectory"); - } - - var compilationFailure = new CompilationFailure( - sourceFilePath, - sourceFileContent, - compilationContent, - group.Select(GetDiagnosticMessage), - additionalMessage); - - failures.Add(compilationFailure); - } - - return new CompilationFailedException(failures); - } - - private static string ReadContent(RazorCodeDocument codeDocument, string filePath) - { - RazorSourceDocument sourceDocument; - if (string.IsNullOrEmpty(filePath) || string.Equals(codeDocument.Source.FilePath, filePath, StringComparison.Ordinal)) - { - sourceDocument = codeDocument.Source; - } - else - { - sourceDocument = codeDocument.Imports.FirstOrDefault(f => string.Equals(f.FilePath, filePath, StringComparison.Ordinal)); - } - - if (sourceDocument != null) - { - var contentChars = new char[sourceDocument.Length]; - sourceDocument.CopyTo(0, contentChars, 0, sourceDocument.Length); - return new string(contentChars); - } - - return string.Empty; - } - - private static DiagnosticMessage GetDiagnosticMessage(Diagnostic diagnostic) - { - var mappedLineSpan = diagnostic.Location.GetMappedLineSpan(); - return new DiagnosticMessage( - diagnostic.GetMessage(), - CSharpDiagnosticFormatter.Instance.Format(diagnostic), - mappedLineSpan.Path, - mappedLineSpan.StartLinePosition.Line + 1, - mappedLineSpan.StartLinePosition.Character + 1, - mappedLineSpan.EndLinePosition.Line + 1, - mappedLineSpan.EndLinePosition.Character + 1); - } - - private static DiagnosticMessage CreateDiagnosticMessage( - RazorDiagnostic razorDiagnostic, - string filePath) - { - var sourceSpan = razorDiagnostic.Span; - var message = razorDiagnostic.GetMessage(); - return new DiagnosticMessage( - message: message, - formattedMessage: razorDiagnostic.ToString(), - filePath: filePath, - startLine: sourceSpan.LineIndex + 1, - startColumn: sourceSpan.CharacterIndex, - endLine: sourceSpan.LineIndex + 1, - endColumn: sourceSpan.CharacterIndex + sourceSpan.Length); - } - - private static string GetFilePath(RazorCodeDocument codeDocument, Diagnostic diagnostic) - { - if (diagnostic.Location == Location.None) - { - return codeDocument.Source.FilePath; - } - - return diagnostic.Location.GetMappedLineSpan().Path; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorReferenceManager.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorReferenceManager.cs deleted file mode 100644 index 04965e52a4..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorReferenceManager.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.CodeAnalysis; -using Microsoft.Extensions.Options; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ -#pragma warning disable CS0618 // Type or member is obsolete - public class DefaultRazorReferenceManager : RazorReferenceManager -#pragma warning restore CS0618 // Type or member is obsolete - { - private readonly ApplicationPartManager _partManager; - private readonly IList _additionalMetadataReferences; - private object _compilationReferencesLock = new object(); - private bool _compilationReferencesInitialized; - private IReadOnlyList _compilationReferences; - - public DefaultRazorReferenceManager( - ApplicationPartManager partManager, - IOptions optionsAccessor) - { - _partManager = partManager; -#pragma warning disable CS0618 // Type or member is obsolete - _additionalMetadataReferences = optionsAccessor.Value.AdditionalCompilationReferences; -#pragma warning restore CS0618 // Type or member is obsolete - } - - public override IReadOnlyList CompilationReferences - { - get - { - return LazyInitializer.EnsureInitialized( - ref _compilationReferences, - ref _compilationReferencesInitialized, - ref _compilationReferencesLock, - GetCompilationReferences); - } - } - - private IReadOnlyList GetCompilationReferences() - { -#pragma warning disable CS0618 // Type or member is obsolete - var feature = new MetadataReferenceFeature(); -#pragma warning restore CS0618 // Type or member is obsolete - _partManager.PopulateFeature(feature); - var applicationReferences = feature.MetadataReferences; - - if (_additionalMetadataReferences.Count == 0) - { - return applicationReferences.ToArray(); - } - - var compilationReferences = new List(applicationReferences.Count + _additionalMetadataReferences.Count); - compilationReferences.AddRange(applicationReferences); - compilationReferences.AddRange(_additionalMetadataReferences); - - return compilationReferences; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorViewEngineFileProviderAccessor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorViewEngineFileProviderAccessor.cs deleted file mode 100644 index 5823a4b39c..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DefaultRazorViewEngineFileProviderAccessor.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Options; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - /// - /// Default implementation of . - /// - public class DefaultRazorViewEngineFileProviderAccessor : IRazorViewEngineFileProviderAccessor - { - /// - /// Initializes a new instance of . - /// - /// Accessor to . - public DefaultRazorViewEngineFileProviderAccessor(IOptions optionsAccessor) - { - var fileProviders = optionsAccessor.Value.FileProviders; - if (fileProviders.Count == 0) - { - FileProvider = new NullFileProvider(); - } - else if (fileProviders.Count == 1) - { - FileProvider = fileProviders[0]; - } - else - { - FileProvider = new CompositeFileProvider(fileProviders); - } - } - - /// - /// Gets the used to look up Razor files. - /// - public IFileProvider FileProvider { get; } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ExpressionRewriter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ExpressionRewriter.cs deleted file mode 100644 index 6d3d9cc757..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ExpressionRewriter.cs +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq.Expressions; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - /// - /// An expression rewriter which can hoist a simple expression lambda into a private field. - /// - public class ExpressionRewriter : CSharpSyntaxRewriter - { - private static readonly string FieldNameTemplate = "__h{0}"; - - public ExpressionRewriter(SemanticModel semanticModel) - { - SemanticModel = semanticModel; - - Expressions = new List>(); - } - - // We only want to rewrite expressions for the top-level class definition. - private bool IsInsideClass { get; set; } - - private SemanticModel SemanticModel { get; } - - private List> Expressions { get; } - - public static CSharpCompilation Rewrite(CSharpCompilation compilation) - { - var rewrittenTrees = new List(); - foreach (var tree in compilation.SyntaxTrees) - { - var semanticModel = compilation.GetSemanticModel(tree, ignoreAccessibility: true); - var rewriter = new ExpressionRewriter(semanticModel); - - var rewrittenTree = tree.WithRootAndOptions(rewriter.Visit(tree.GetRoot()), tree.Options); - rewrittenTrees.Add(rewrittenTree); - } - - return compilation.RemoveAllSyntaxTrees().AddSyntaxTrees(rewrittenTrees); - } - - public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node) - { - if (IsInsideClass) - { - // Avoid recursing into nested classes. - return node; - } - - Expressions.Clear(); - - IsInsideClass = true; - - // Call base first to visit all the children and populate Expressions. - var classDeclaration = (ClassDeclarationSyntax)base.VisitClassDeclaration(node); - - IsInsideClass = false; - - var memberDeclarations = new List(); - foreach (var kvp in Expressions) - { - var expression = kvp.Key; - var memberName = kvp.Value.GetFirstToken(); - - var expressionType = SemanticModel.GetTypeInfo(expression).ConvertedType; - var declaration = SyntaxFactory.FieldDeclaration( - SyntaxFactory.List(), - SyntaxFactory.TokenList( - SyntaxFactory.Token(SyntaxKind.PrivateKeyword), - SyntaxFactory.Token(SyntaxKind.StaticKeyword), - SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)), - SyntaxFactory.VariableDeclaration( - SyntaxFactory.ParseTypeName(expressionType.ToDisplayString( - SymbolDisplayFormat.FullyQualifiedFormat)), - SyntaxFactory.SingletonSeparatedList( - SyntaxFactory.VariableDeclarator( - memberName, - SyntaxFactory.BracketedArgumentList(), - SyntaxFactory.EqualsValueClause(expression))))) - .WithTriviaFrom(expression); - memberDeclarations.Add(declaration); - } - - return classDeclaration.AddMembers(memberDeclarations.ToArray()); - } - - public override SyntaxNode VisitSimpleLambdaExpression(SimpleLambdaExpressionSyntax node) - { - Debug.Assert(IsInsideClass); - - // If this lambda is an Expression and is suitable for hoisting, we rewrite this into a field access. - // - // Before: - // public Task ExecuteAsync(...) - // { - // ... - // Html.EditorFor(m => m.Price); - // ... - // } - // - // - // After: - // private static readonly Expression> __h0 = m => m.Price; - // public Task ExecuteAsync(...) - // { - // ... - // Html.EditorFor(__h0); - // ... - // } - // - var type = SemanticModel.GetTypeInfo(node); - - // Due to an anomaly where Roslyn (depending on code sample) may finish compilation without diagnostic - // errors (this code path does not execute when diagnostic errors are present) we need to validate that - // the ConvertedType was determined/is not null. - if (type.ConvertedType == null || - type.ConvertedType.Name != typeof(Expression).Name && - type.ConvertedType.ContainingNamespace.Name != typeof(Expression).Namespace) - { - return node; - } - - if (!node.Parent.IsKind(SyntaxKind.Argument)) - { - return node; - } - - var parameter = node.Parameter; - if (IsValidForHoisting(parameter, node.Body)) - { - // Replace with a MemberAccess - var memberName = string.Format(FieldNameTemplate, Expressions.Count); - var memberAccess = PadMemberAccess(node, SyntaxFactory.IdentifierName(memberName)); - Expressions.Add(new KeyValuePair(node, memberAccess)); - return memberAccess; - } - - return node; - } - - private static IdentifierNameSyntax PadMemberAccess( - SimpleLambdaExpressionSyntax node, - IdentifierNameSyntax memberAccess) - { - var charactersToExclude = memberAccess.Identifier.Text.Length; - var triviaList = new SyntaxTriviaList(); - - // Go through each token and - // 1. Append leading trivia - // 2. Append the same number of whitespace as the length of the token text - // 3. Append trailing trivia - foreach (var token in node.DescendantTokens()) - { - if (token.HasLeadingTrivia) - { - triviaList = triviaList.AddRange(token.LeadingTrivia); - } - - // Need to exclude the length of the member name from the padding. - var padding = token.Text.Length; - if (padding > charactersToExclude) - { - padding -= charactersToExclude; - charactersToExclude = 0; - } - else - { - charactersToExclude -= padding; - padding = 0; - } - - if (padding > 0) - { - triviaList = triviaList.Add(SyntaxFactory.Whitespace(new string(' ', padding))); - } - - if (token.HasTrailingTrivia) - { - triviaList = triviaList.AddRange(token.TrailingTrivia); - } - } - - return memberAccess - .WithLeadingTrivia(node.GetLeadingTrivia()) - .WithTrailingTrivia(triviaList); - } - - private static bool IsValidForHoisting(ParameterSyntax parameter, CSharpSyntaxNode node) - { - if (node.IsKind(SyntaxKind.IdentifierName)) - { - var identifier = (IdentifierNameSyntax)node; - if (identifier.Identifier.Text == parameter.Identifier.Text) - { - return true; - } - } - else if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression)) - { - var memberAccess = (MemberAccessExpressionSyntax)node; - var lhs = memberAccess.Expression; - return IsValidForHoisting(parameter, lhs); - } - - return false; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/FileProviderRazorProject.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/FileProviderRazorProject.cs deleted file mode 100644 index 9e5718fa2f..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/FileProviderRazorProject.cs +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.Extensions.FileProviders; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public class FileProviderRazorProjectFileSystem : RazorProjectFileSystem - { - private const string RazorFileExtension = ".cshtml"; - private readonly IFileProvider _provider; - private readonly IHostingEnvironment _hostingEnvironment; - - public FileProviderRazorProjectFileSystem(IRazorViewEngineFileProviderAccessor accessor, IHostingEnvironment hostingEnvironment) - { - if (accessor == null) - { - throw new ArgumentNullException(nameof(accessor)); - } - - if (hostingEnvironment == null) - { - throw new ArgumentNullException(nameof(hostingEnvironment)); - } - - _provider = accessor.FileProvider; - _hostingEnvironment = hostingEnvironment; - } - - public override RazorProjectItem GetItem(string path) - { - path = NormalizeAndEnsureValidPath(path); - var fileInfo = _provider.GetFileInfo(path); - - return new FileProviderRazorProjectItem(fileInfo, basePath: string.Empty, filePath: path, root: _hostingEnvironment.ContentRootPath); - } - - public override IEnumerable EnumerateItems(string path) - { - path = NormalizeAndEnsureValidPath(path); - return EnumerateFiles(_provider.GetDirectoryContents(path), path, prefix: string.Empty); - } - - private IEnumerable EnumerateFiles(IDirectoryContents directory, string basePath, string prefix) - { - if (directory.Exists) - { - foreach (var fileInfo in directory) - { - if (fileInfo.IsDirectory) - { - var relativePath = prefix + "/" + fileInfo.Name; - var subDirectory = _provider.GetDirectoryContents(JoinPath(basePath, relativePath)); - var children = EnumerateFiles(subDirectory, basePath, relativePath); - foreach (var child in children) - { - yield return child; - } - } - else if (string.Equals(RazorFileExtension, Path.GetExtension(fileInfo.Name), StringComparison.OrdinalIgnoreCase)) - { - var filePath = prefix + "/" + fileInfo.Name; - - yield return new FileProviderRazorProjectItem(fileInfo, basePath, filePath: filePath, root: _hostingEnvironment.ContentRootPath); - } - } - } - } - - private static string JoinPath(string path1, string path2) - { - var hasTrailingSlash = path1.EndsWith("/", StringComparison.Ordinal); - var hasLeadingSlash = path2.StartsWith("/", StringComparison.Ordinal); - if (hasLeadingSlash && hasTrailingSlash) - { - return path1 + path2.Substring(1); - } - else if (hasLeadingSlash || hasTrailingSlash) - { - return path1 + path2; - } - - return path1 + "/" + path2; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/FileProviderRazorProjectItem.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/FileProviderRazorProjectItem.cs deleted file mode 100644 index 6108d6875b..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/FileProviderRazorProjectItem.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.Extensions.FileProviders; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public class FileProviderRazorProjectItem : RazorProjectItem - { - private string _root; - private string _relativePhysicalPath; - private bool _isRelativePhysicalPathSet; - - public FileProviderRazorProjectItem(IFileInfo fileInfo, string basePath, string filePath, string root) - { - FileInfo = fileInfo; - BasePath = basePath; - FilePath = filePath; - _root = root; - } - - public IFileInfo FileInfo { get; } - - public override string BasePath { get; } - - public override string FilePath { get; } - - public override bool Exists => FileInfo.Exists; - - public override string PhysicalPath => FileInfo.PhysicalPath; - - public override string RelativePhysicalPath - { - get - { - if (!_isRelativePhysicalPathSet) - { - _isRelativePhysicalPathSet = true; - - if (Exists) - { - if (_root != null && - !string.IsNullOrEmpty(PhysicalPath) && - PhysicalPath.StartsWith(_root, StringComparison.OrdinalIgnoreCase) && - PhysicalPath.Length > _root.Length && - (PhysicalPath[_root.Length] == Path.DirectorySeparatorChar || PhysicalPath[_root.Length] == Path.AltDirectorySeparatorChar)) - { - _relativePhysicalPath = PhysicalPath.Substring(_root.Length + 1); // Include leading separator - } - } - } - - return _relativePhysicalPath; - } - } - - public override Stream Read() - { - return FileInfo.CreateReadStream(); - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/IRazorViewEngineFileProviderAccessor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/IRazorViewEngineFileProviderAccessor.cs deleted file mode 100644 index 670b7c3db3..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/IRazorViewEngineFileProviderAccessor.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.FileProviders; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - /// - /// Accessor to the used by . - /// - public interface IRazorViewEngineFileProviderAccessor - { - /// - /// Gets the used to look up Razor files. - /// - IFileProvider FileProvider { get; } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/LazyMetadataReferenceFeature.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/LazyMetadataReferenceFeature.cs deleted file mode 100644 index 5479991463..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/LazyMetadataReferenceFeature.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Razor; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public class LazyMetadataReferenceFeature : IMetadataReferenceFeature - { -#pragma warning disable CS0618 // Type or member is obsolete - private readonly RazorReferenceManager _referenceManager; -#pragma warning restore CS0618 // Type or member is obsolete - -#pragma warning disable CS0618 // Type or member is obsolete - public LazyMetadataReferenceFeature(RazorReferenceManager referenceManager) -#pragma warning restore CS0618 // Type or member is obsolete - { - _referenceManager = referenceManager; - } - - /// - /// Invoking ensures that compilation - /// references are lazily evaluated. - /// - public IReadOnlyList References => _referenceManager.CompilationReferences; - - public RazorEngine Engine { get; set; } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorDiagnosticSourceExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorDiagnosticSourceExtensions.cs deleted file mode 100644 index a60f5fb587..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorDiagnosticSourceExtensions.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc.Rendering; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public static class MvcRazorDiagnosticSourceExtensions - { - public static void BeforeViewPage( - this DiagnosticSource diagnosticSource, - IRazorPage page, - ViewContext viewContext) - { - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage", - new - { - page = page, - viewContext = viewContext, - actionDescriptor = viewContext.ActionDescriptor, - httpContext = viewContext.HttpContext, - }); - } - } - - public static void AfterViewPage( - this DiagnosticSource diagnosticSource, - IRazorPage page, - ViewContext viewContext) - { - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.AfterViewPage")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.Razor.AfterViewPage", - new - { - page = page, - viewContext = viewContext, - actionDescriptor = viewContext.ActionDescriptor, - httpContext = viewContext.HttpContext, - }); - } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs deleted file mode 100644 index 0f43c19f44..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompiler.cs +++ /dev/null @@ -1,475 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.AspNetCore.Razor.Hosting; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.Emit; -using Microsoft.CodeAnalysis.Text; -using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Primitives; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - /// - /// Caches the result of runtime compilation of Razor files for the duration of the application lifetime. - /// - public class RazorViewCompiler : IViewCompiler - { - private readonly object _cacheLock = new object(); - private readonly Dictionary _precompiledViews; - private readonly ConcurrentDictionary _normalizedPathCache; - private readonly IFileProvider _fileProvider; - private readonly RazorProjectEngine _projectEngine; - private readonly Action _compilationCallback; - private readonly IMemoryCache _cache; - private readonly ILogger _logger; - private readonly CSharpCompiler _csharpCompiler; - - public RazorViewCompiler( - IFileProvider fileProvider, - RazorProjectEngine projectEngine, - CSharpCompiler csharpCompiler, - Action compilationCallback, - IList precompiledViews, - IMemoryCache cache, - ILogger logger) - { - if (fileProvider == null) - { - throw new ArgumentNullException(nameof(fileProvider)); - } - - if (projectEngine == null) - { - throw new ArgumentNullException(nameof(projectEngine)); - } - - if (csharpCompiler == null) - { - throw new ArgumentNullException(nameof(csharpCompiler)); - } - - if (compilationCallback == null) - { - throw new ArgumentNullException(nameof(compilationCallback)); - } - - if (precompiledViews == null) - { - throw new ArgumentNullException(nameof(precompiledViews)); - } - - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } - - _fileProvider = fileProvider; - _projectEngine = projectEngine; - _csharpCompiler = csharpCompiler; - _compilationCallback = compilationCallback; - _logger = logger; - - - _normalizedPathCache = new ConcurrentDictionary(StringComparer.Ordinal); - - // This is our L0 cache, and is a durable store. Views migrate into the cache as they are requested - // from either the set of known precompiled views, or by being compiled. - _cache = cache; - - // We need to validate that the all of the precompiled views are unique by path (case-insensitive). - // We do this because there's no good way to canonicalize paths on windows, and it will create - // problems when deploying to linux. Rather than deal with these issues, we just don't support - // views that differ only by case. - _precompiledViews = new Dictionary( - precompiledViews.Count, - StringComparer.OrdinalIgnoreCase); - - foreach (var precompiledView in precompiledViews) - { - logger.ViewCompilerLocatedCompiledView(precompiledView.RelativePath); - - if (!_precompiledViews.ContainsKey(precompiledView.RelativePath)) - { - // View ordering has precedence semantics, a view with a higher precedence was - // already added to the list. - _precompiledViews.Add(precompiledView.RelativePath, precompiledView); - } - } - - if (_precompiledViews.Count == 0) - { - logger.ViewCompilerNoCompiledViewsFound(); - } - } - - public bool AllowRecompilingViewsOnFileChange { get; set; } - - /// - public Task CompileAsync(string relativePath) - { - if (relativePath == null) - { - throw new ArgumentNullException(nameof(relativePath)); - } - - // Attempt to lookup the cache entry using the passed in path. This will succeed if the path is already - // normalized and a cache entry exists. - if (_cache.TryGetValue(relativePath, out Task cachedResult)) - { - return cachedResult; - } - - var normalizedPath = GetNormalizedPath(relativePath); - if (_cache.TryGetValue(normalizedPath, out cachedResult)) - { - return cachedResult; - } - - // Entry does not exist. Attempt to create one. - cachedResult = OnCacheMiss(normalizedPath); - return cachedResult; - } - - private Task OnCacheMiss(string normalizedPath) - { - ViewCompilerWorkItem item; - TaskCompletionSource taskSource; - MemoryCacheEntryOptions cacheEntryOptions; - - // Safe races cannot be allowed when compiling Razor pages. To ensure only one compilation request succeeds - // per file, we'll lock the creation of a cache entry. Creating the cache entry should be very quick. The - // actual work for compiling files happens outside the critical section. - lock (_cacheLock) - { - // Double-checked locking to handle a possible race. - if (_cache.TryGetValue(normalizedPath, out Task result)) - { - return result; - } - - if (_precompiledViews.TryGetValue(normalizedPath, out var precompiledView)) - { - _logger.ViewCompilerLocatedCompiledViewForPath(normalizedPath); - item = CreatePrecompiledWorkItem(normalizedPath, precompiledView); - } - else - { - item = CreateRuntimeCompilationWorkItem(normalizedPath); - } - - // At this point, we've decided what to do - but we should create the cache entry and - // release the lock first. - cacheEntryOptions = new MemoryCacheEntryOptions(); - - Debug.Assert(item.ExpirationTokens != null); - for (var i = 0; i < item.ExpirationTokens.Count; i++) - { - cacheEntryOptions.ExpirationTokens.Add(item.ExpirationTokens[i]); - } - - taskSource = new TaskCompletionSource(creationOptions: TaskCreationOptions.RunContinuationsAsynchronously); - if (item.SupportsCompilation) - { - // We'll compile in just a sec, be patient. - } - else - { - // If we can't compile, we should have already created the descriptor - Debug.Assert(item.Descriptor != null); - taskSource.SetResult(item.Descriptor); - } - - _cache.Set(normalizedPath, taskSource.Task, cacheEntryOptions); - } - - // Now the lock has been released so we can do more expensive processing. - if (item.SupportsCompilation) - { - Debug.Assert(taskSource != null); - - if (item.Descriptor?.Item != null && - ChecksumValidator.IsItemValid(_projectEngine.FileSystem, item.Descriptor.Item)) - { - // If the item has checksums to validate, we should also have a precompiled view. - Debug.Assert(item.Descriptor != null); - - taskSource.SetResult(item.Descriptor); - return taskSource.Task; - } - - _logger.ViewCompilerInvalidingCompiledFile(item.NormalizedPath); - try - { - var descriptor = CompileAndEmit(normalizedPath); - descriptor.ExpirationTokens = cacheEntryOptions.ExpirationTokens; - taskSource.SetResult(descriptor); - } - catch (Exception ex) - { - taskSource.SetException(ex); - } - } - - return taskSource.Task; - } - - private ViewCompilerWorkItem CreatePrecompiledWorkItem(string normalizedPath, CompiledViewDescriptor precompiledView) - { - // We have a precompiled view - but we're not sure that we can use it yet. - // - // We need to determine first if we have enough information to 'recompile' this view. If that's the case - // we'll create change tokens for all of the files. - // - // Then we'll attempt to validate if any of those files have different content than the original sources - // based on checksums. - if (precompiledView.Item == null || !ChecksumValidator.IsRecompilationSupported(precompiledView.Item)) - { - return new ViewCompilerWorkItem() - { - // If we don't have a checksum for the primary source file we can't recompile. - SupportsCompilation = false, - - ExpirationTokens = Array.Empty(), // Never expire because we can't recompile. - Descriptor = precompiledView, // This will be used as-is. - }; - } - - var item = new ViewCompilerWorkItem() - { - SupportsCompilation = true, - - Descriptor = precompiledView, // This might be used, if the checksums match. - - // Used to validate and recompile - NormalizedPath = normalizedPath, - - ExpirationTokens = GetExpirationTokens(precompiledView), - }; - - // We also need to create a new descriptor, because the original one doesn't have expiration tokens on - // it. These will be used by the view location cache, which is like an L1 cache for views (this class is - // the L2 cache). - item.Descriptor = new CompiledViewDescriptor() - { - ExpirationTokens = item.ExpirationTokens, - IsPrecompiled = true, - Item = precompiledView.Item, - RelativePath = precompiledView.RelativePath, - ViewAttribute = precompiledView.ViewAttribute, - }; - - return item; - } - - private ViewCompilerWorkItem CreateRuntimeCompilationWorkItem(string normalizedPath) - { - IList expirationTokens = Array.Empty(); - - if (AllowRecompilingViewsOnFileChange) - { - var changeToken = _fileProvider.Watch(normalizedPath); - expirationTokens = new List { changeToken }; - } - - var projectItem = _projectEngine.FileSystem.GetItem(normalizedPath); - if (!projectItem.Exists) - { - _logger.ViewCompilerCouldNotFindFileAtPath(normalizedPath); - - // If the file doesn't exist, we can't do compilation right now - we still want to cache - // the fact that we tried. This will allow us to re-trigger compilation if the view file - // is added. - return new ViewCompilerWorkItem() - { - // We don't have enough information to compile - SupportsCompilation = false, - - Descriptor = new CompiledViewDescriptor() - { - RelativePath = normalizedPath, - ExpirationTokens = expirationTokens, - }, - - // We can try again if the file gets created. - ExpirationTokens = expirationTokens, - }; - } - - _logger.ViewCompilerFoundFileToCompile(normalizedPath); - - GetChangeTokensFromImports(expirationTokens, projectItem); - - return new ViewCompilerWorkItem() - { - SupportsCompilation = true, - - NormalizedPath = normalizedPath, - ExpirationTokens = expirationTokens, - }; - } - - private IList GetExpirationTokens(CompiledViewDescriptor precompiledView) - { - if (!AllowRecompilingViewsOnFileChange) - { - return Array.Empty(); - } - - var checksums = precompiledView.Item.GetChecksumMetadata(); - var expirationTokens = new List(checksums.Count); - - for (var i = 0; i < checksums.Count; i++) - { - // We rely on Razor to provide the right set of checksums. Trust the compiler, it has to do a good job, - // so it probably will. - expirationTokens.Add(_fileProvider.Watch(checksums[i].Identifier)); - } - - return expirationTokens; - } - - private void GetChangeTokensFromImports(IList expirationTokens, RazorProjectItem projectItem) - { - if (!AllowRecompilingViewsOnFileChange) - { - return; - } - - // OK this means we can do compilation. For now let's just identify the other files we need to watch - // so we can create the cache entry. Compilation will happen after we release the lock. - var importFeature = _projectEngine.ProjectFeatures.OfType().FirstOrDefault(); - - // There should always be an import feature unless someone has misconfigured their RazorProjectEngine. - // In that case once we attempt to parse the Razor file we'll explode and give the a user a decent - // error message; for now, lets just be extra protective and assume 0 imports to not give a bad error. - var imports = importFeature?.GetImports(projectItem) ?? Enumerable.Empty(); - var physicalImports = imports.Where(import => import.FilePath != null); - - // Now that we have non-dynamic imports we need to get their RazorProjectItem equivalents so we have their - // physical file paths (according to the FileSystem). - foreach (var physicalImport in physicalImports) - { - expirationTokens.Add(_fileProvider.Watch(physicalImport.FilePath)); - } - } - - protected virtual CompiledViewDescriptor CompileAndEmit(string relativePath) - { - var projectItem = _projectEngine.FileSystem.GetItem(relativePath); - var codeDocument = _projectEngine.Process(projectItem); - var cSharpDocument = codeDocument.GetCSharpDocument(); - - if (cSharpDocument.Diagnostics.Count > 0) - { - throw CompilationFailedExceptionFactory.Create( - codeDocument, - cSharpDocument.Diagnostics); - } - - var assembly = CompileAndEmit(codeDocument, cSharpDocument.GeneratedCode); - - // Anything we compile from source will use Razor 2.1 and so should have the new metadata. - var loader = new RazorCompiledItemLoader(); - var item = loader.LoadItems(assembly).SingleOrDefault(); - var attribute = assembly.GetCustomAttribute(); - - return new CompiledViewDescriptor(item, attribute); - } - - internal Assembly CompileAndEmit(RazorCodeDocument codeDocument, string generatedCode) - { - _logger.GeneratedCodeToAssemblyCompilationStart(codeDocument.Source.FilePath); - - var startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0; - - var assemblyName = Path.GetRandomFileName(); - var compilation = CreateCompilation(generatedCode, assemblyName); - - var emitOptions = _csharpCompiler.EmitOptions; - var emitPdbFile = _csharpCompiler.EmitPdb && emitOptions.DebugInformationFormat != DebugInformationFormat.Embedded; - - using (var assemblyStream = new MemoryStream()) - using (var pdbStream = emitPdbFile ? new MemoryStream() : null) - { - var result = compilation.Emit( - assemblyStream, - pdbStream, - options: emitOptions); - - if (!result.Success) - { - throw CompilationFailedExceptionFactory.Create( - codeDocument, - generatedCode, - assemblyName, - result.Diagnostics); - } - - assemblyStream.Seek(0, SeekOrigin.Begin); - pdbStream?.Seek(0, SeekOrigin.Begin); - - var assembly = Assembly.Load(assemblyStream.ToArray(), pdbStream?.ToArray()); - _logger.GeneratedCodeToAssemblyCompilationEnd(codeDocument.Source.FilePath, startTimestamp); - - return assembly; - } - } - - private CSharpCompilation CreateCompilation(string compilationContent, string assemblyName) - { - var sourceText = SourceText.From(compilationContent, Encoding.UTF8); - var syntaxTree = _csharpCompiler.CreateSyntaxTree(sourceText).WithFilePath(assemblyName); - var compilation = _csharpCompiler - .CreateCompilation(assemblyName) - .AddSyntaxTrees(syntaxTree); - compilation = ExpressionRewriter.Rewrite(compilation); - - var compilationContext = new RoslynCompilationContext(compilation); - _compilationCallback(compilationContext); - compilation = compilationContext.Compilation; - return compilation; - } - - private string GetNormalizedPath(string relativePath) - { - Debug.Assert(relativePath != null); - if (relativePath.Length == 0) - { - return relativePath; - } - - if (!_normalizedPathCache.TryGetValue(relativePath, out var normalizedPath)) - { - normalizedPath = ViewPath.NormalizePath(relativePath); - _normalizedPathCache[relativePath] = normalizedPath; - } - - return normalizedPath; - } - - private class ViewCompilerWorkItem - { - public bool SupportsCompilation { get; set; } - - public string NormalizedPath { get; set; } - - public IList ExpirationTokens { get; set; } - - public CompiledViewDescriptor Descriptor { get; set; } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompilerProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompilerProvider.cs deleted file mode 100644 index 3776bc845f..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorViewCompilerProvider.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using Microsoft.AspNetCore.Mvc.ApplicationParts; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - public class RazorViewCompilerProvider : IViewCompilerProvider - { - private readonly RazorProjectEngine _razorProjectEngine; - private readonly ApplicationPartManager _applicationPartManager; - private readonly IRazorViewEngineFileProviderAccessor _fileProviderAccessor; - private readonly CSharpCompiler _csharpCompiler; - private readonly IViewCompilationMemoryCacheProvider _compilationMemoryCacheProvider; - private readonly RazorViewEngineOptions _viewEngineOptions; - private readonly ILogger _logger; - private readonly Func _createCompiler; - - private object _initializeLock = new object(); - private bool _initialized; - private IViewCompiler _compiler; - - public RazorViewCompilerProvider( - ApplicationPartManager applicationPartManager, - RazorProjectEngine razorProjectEngine, - IRazorViewEngineFileProviderAccessor fileProviderAccessor, - CSharpCompiler csharpCompiler, - IOptions viewEngineOptionsAccessor, - IViewCompilationMemoryCacheProvider compilationMemoryCacheProvider, - ILoggerFactory loggerFactory) - { - _applicationPartManager = applicationPartManager; - _razorProjectEngine = razorProjectEngine; - _fileProviderAccessor = fileProviderAccessor; - _csharpCompiler = csharpCompiler; - _compilationMemoryCacheProvider = compilationMemoryCacheProvider; - _viewEngineOptions = viewEngineOptionsAccessor.Value; - - _logger = loggerFactory.CreateLogger(); - _createCompiler = CreateCompiler; - } - - public IViewCompiler GetCompiler() - { - var fileProvider = _fileProviderAccessor.FileProvider; - if (fileProvider is NullFileProvider) - { - var message = Resources.FormatFileProvidersAreRequired( - typeof(RazorViewEngineOptions).FullName, - nameof(RazorViewEngineOptions.FileProviders), - typeof(IFileProvider).FullName); - throw new InvalidOperationException(message); - } - - return LazyInitializer.EnsureInitialized( - ref _compiler, - ref _initialized, - ref _initializeLock, - _createCompiler); - } - - private IViewCompiler CreateCompiler() - { - var feature = new ViewsFeature(); - _applicationPartManager.PopulateFeature(feature); - - return new RazorViewCompiler( - _fileProviderAccessor.FileProvider, - _razorProjectEngine, - _csharpCompiler, -#pragma warning disable CS0618 // Type or member is obsolete - _viewEngineOptions.CompilationCallback, -#pragma warning restore CS0618 // Type or member is obsolete - feature.ViewDescriptors, - _compilationMemoryCacheProvider.CompilationMemoryCache, - _logger) - { - AllowRecompilingViewsOnFileChange = _viewEngineOptions.AllowRecompilingViewsOnFileChange, - }; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/SymbolsUtility.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/SymbolsUtility.cs deleted file mode 100644 index 280fe8c84a..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/SymbolsUtility.cs +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Runtime.InteropServices; - -namespace Microsoft.AspNetCore.Mvc.Razor.Internal -{ - /// - /// Utility type for determining if a platform supports full pdb file generation. - /// - internal static class SymbolsUtility - { - // Native pdb writer's CLSID - private const string SymWriterGuid = "0AE2DEB0-F901-478b-BB9F-881EE8066788"; - - /// - /// Determines if the current platform supports full pdb generation. - /// - /// true if full pdb generation is supported; false otherwise. - public static bool SupportsFullPdbGeneration() - { - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - // Cross-plat always produce portable pdbs. - return false; - } - - if (Type.GetType("Mono.Runtime") != null) - { - return false; - } - - try - { - // Check for the pdb writer component that roslyn uses to generate pdbs - var type = Marshal.GetTypeFromCLSID(new Guid(SymWriterGuid)); - if (type != null) - { - // This line will throw if pdb generation is not supported. - Activator.CreateInstance(type); - return true; - } - } - catch - { - } - - return false; - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs index 1ed92110bc..94338ef371 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/LanguageViewLocationExpander.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor } /// - /// Instantiates a new instance. + /// Instantiates a new instance. /// /// The . public LanguageViewLocationExpander(LanguageViewLocationExpanderFormat format) @@ -112,4 +112,4 @@ namespace Microsoft.AspNetCore.Mvc.Razor } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Microsoft.AspNetCore.Mvc.Razor.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Microsoft.AspNetCore.Mvc.Razor.csproj index 4bef4f811f..6936a83ba6 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Microsoft.AspNetCore.Mvc.Razor.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Microsoft.AspNetCore.Mvc.Razor.csproj @@ -2,59 +2,18 @@ ASP.NET Core MVC Razor view engine for CSHTML files. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc;cshtml;razor - $(MSBuildProjectName).nuspec - true - - - - - - - - - - - - true - - id=$(MSBuildProjectName); - version=$(PackageVersion); - authors=$(Authors); - licenseUrl=$(PackageLicenseUrl); - projectUrl=$(PackageProjectUrl); - iconUrl=$(PackageIconUrl); - copyright=$(Copyright); - description=$(Description); - tags=$([MSBuild]::Escape($(PackageTags))); - serviceable=$(Serviceable); - repositoryUrl=$(RepositoryUrl); - repositoryCommit=$(RepositoryCommit); - targetframework=$(TargetFramework); - MicrosoftAspNetCoreMvcRazorExtensionsPackageVersion=$(MicrosoftAspNetCoreMvcRazorExtensionsPackageVersion); - MicrosoftAspNetCoreRazorRuntimePackageVersion=$(MicrosoftAspNetCoreRazorRuntimePackageVersion); - MicrosoftCodeAnalysisRazorPackageVersion=$(MicrosoftCodeAnalysisRazorPackageVersion); - MicrosoftCodeAnalysisCSharpPackageVersion=$(MicrosoftCodeAnalysisCSharpPackageVersion); - MicrosoftExtensionsCachingMemoryPackageVersion=$(MicrosoftExtensionsCachingMemoryPackageVersion); - MicrosoftExtensionsFileProvidersCompositePackageVersion=$(MicrosoftExtensionsFileProvidersCompositePackageVersion); - MicrosoftDiaSymReaderNativePackageVersion=$(MicrosoftDiaSymReaderNativePackageVersion); - OutputBinary=@(BuiltProjectOutputGroupOutput); - OutputDocumentation=@(DocumentationProjectOutputGroupOutput); - OutputSymbol=@(DebugSymbolsProjectOutputGroupOutput); - - - diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Microsoft.AspNetCore.Mvc.Razor.nuspec b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Microsoft.AspNetCore.Mvc.Razor.nuspec deleted file mode 100644 index 9ff2439b96..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Microsoft.AspNetCore.Mvc.Razor.nuspec +++ /dev/null @@ -1,44 +0,0 @@ - - - - $id$ - $version$ - $authors$ - true - $licenseUrl$ - $projectUrl$ - $iconUrl$ - $description$ - $copyright$ - $tags$ - $serviceable$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/MvcRazorDiagnosticSourceExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/MvcRazorDiagnosticSourceExtensions.cs new file mode 100644 index 0000000000..f0479ef143 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/MvcRazorDiagnosticSourceExtensions.cs @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Diagnostics; +using Microsoft.AspNetCore.Mvc.Rendering; + +namespace Microsoft.AspNetCore.Mvc.Razor +{ + internal static class MvcRazorDiagnosticSourceExtensions + { + public static void BeforeViewPage( + this DiagnosticListener diagnosticListener, + IRazorPage page, + ViewContext viewContext) + { + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeViewPageImpl(diagnosticListener, page, viewContext); + } + } + + private static void BeforeViewPageImpl( + this DiagnosticListener diagnosticListener, + IRazorPage page, + ViewContext viewContext) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.Razor.BeforeViewPage", + new + { + page = page, + viewContext = viewContext, + actionDescriptor = viewContext.ActionDescriptor, + httpContext = viewContext.HttpContext, + }); + } + } + + public static void AfterViewPage( + this DiagnosticListener diagnosticListener, + IRazorPage page, + ViewContext viewContext) + { + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterViewPageImpl(diagnosticListener, page, viewContext); + } + } + + private static void AfterViewPageImpl( + this DiagnosticListener diagnosticListener, + IRazorPage page, + ViewContext viewContext) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.Razor.AfterViewPage")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.Razor.AfterViewPage", + new + { + page = page, + viewContext = viewContext, + actionDescriptor = viewContext.ActionDescriptor, + httpContext = viewContext.HttpContext, + }); + } + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorLoggerExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/MvcRazorLoggerExtensions.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorLoggerExtensions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/MvcRazorLoggerExtensions.cs index 21d7496abd..58a1123cc7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/MvcRazorLoggerExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/MvcRazorLoggerExtensions.cs @@ -2,14 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { - public static class MvcRazorLoggerExtensions + internal static class MvcRazorLoggerExtensions { private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Properties/AssemblyInfo.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Properties/AssemblyInfo.cs index 0e1a8e8695..5bd88d4693 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Properties/AssemblyInfo.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Properties/AssemblyInfo.cs @@ -10,3 +10,5 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.Razor.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.RazorPages.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Mvc.TagHelpers.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorFileHierarchy.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorFileHierarchy.cs new file mode 100644 index 0000000000..89f7b43dd2 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorFileHierarchy.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.AspNetCore.Mvc.Razor +{ + internal static class RazorFileHierarchy + { + private const string ViewStartFileName = "_ViewStart.cshtml"; + + public static IEnumerable GetViewStartPaths(string path) + { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path)); + } + + if (path[0] != '/') + { + throw new ArgumentException(Resources.RazorProject_PathMustStartWithForwardSlash, nameof(path)); + } + + if (path.Length == 1) + { + yield break; + } + + var builder = new StringBuilder(path); + var maxIterations = 255; + var index = path.Length; + while (maxIterations-- > 0 && index > 1 && (index = path.LastIndexOf('/', index - 1)) != -1) + { + builder.Length = index + 1; + builder.Append(ViewStartFileName); + + var itemPath = builder.ToString(); + yield return itemPath; + } + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs index cc9a20c8cb..9acc858e5a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.Reflection; using System.Text.Encodings.Web; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs index 016076520f..8f2a98defa 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs @@ -16,7 +16,7 @@ using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Buffers; using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.DependencyInjection; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorPagePropertyActivator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPagePropertyActivator.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorPagePropertyActivator.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPagePropertyActivator.cs index b163088361..5bcba01b62 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/RazorPagePropertyActivator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorPagePropertyActivator.cs @@ -6,15 +6,15 @@ using System.Diagnostics; using System.Reflection; using System.Text.Encodings.Web; using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { - public class RazorPagePropertyActivator + internal class RazorPagePropertyActivator { private readonly IModelMetadataProvider _metadataProvider; private readonly Func _rootFactory; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs index 10ef8139da..8b5b3ebe90 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorView.cs @@ -9,8 +9,7 @@ using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewEngines; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; -using Microsoft.AspNetCore.Mvc.Razor.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Buffers; using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Mvc.Razor @@ -24,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor private readonly IRazorViewEngine _viewEngine; private readonly IRazorPageActivator _pageActivator; private readonly HtmlEncoder _htmlEncoder; - private readonly DiagnosticSource _diagnosticSource; + private readonly DiagnosticListener _diagnosticListener; private IViewBufferScope _bufferScope; /// @@ -36,14 +35,14 @@ namespace Microsoft.AspNetCore.Mvc.Razor /// /// The instance to execute. /// The HTML encoder. - /// The . + /// The . public RazorView( IRazorViewEngine viewEngine, IRazorPageActivator pageActivator, IReadOnlyList viewStartPages, IRazorPage razorPage, HtmlEncoder htmlEncoder, - DiagnosticSource diagnosticSource) + DiagnosticListener diagnosticListener) { if (viewEngine == null) { @@ -70,9 +69,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor throw new ArgumentNullException(nameof(htmlEncoder)); } - if (diagnosticSource == null) + if (diagnosticListener == null) { - throw new ArgumentNullException(nameof(diagnosticSource)); + throw new ArgumentNullException(nameof(diagnosticListener)); } _viewEngine = viewEngine; @@ -80,7 +79,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor ViewStartPages = viewStartPages; RazorPage = razorPage; _htmlEncoder = htmlEncoder; - _diagnosticSource = diagnosticSource; + _diagnosticListener = diagnosticListener; } /// @@ -171,7 +170,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor OnAfterPageActivated?.Invoke(page, context); - _diagnosticSource.BeforeViewPage(page, context); + _diagnosticListener.BeforeViewPage(page, context); try { @@ -179,7 +178,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor } finally { - _diagnosticSource.AfterViewPage(page, context); + _diagnosticListener.AfterViewPage(page, context); } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs index 8d929fb883..ad87fbb64b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngine.cs @@ -7,10 +7,8 @@ using System.Diagnostics; using System.Globalization; using System.Linq; using System.Text.Encodings.Web; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.Razor.Internal; +using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewEngines; -using Microsoft.AspNetCore.Razor.Language; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -30,7 +28,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor public class RazorViewEngine : IRazorViewEngine { public static readonly string ViewExtension = ".cshtml"; - private const string ViewStartFileName = "_ViewStart.cshtml"; private const string AreaKey = "area"; private const string ControllerKey = "controller"; @@ -43,21 +40,18 @@ namespace Microsoft.AspNetCore.Mvc.Razor private readonly HtmlEncoder _htmlEncoder; private readonly ILogger _logger; private readonly RazorViewEngineOptions _options; - private readonly RazorProject _razorFileSystem; - private readonly DiagnosticSource _diagnosticSource; + private readonly DiagnosticListener _diagnosticListener; /// /// Initializes a new instance of the . /// - [Obsolete("This constructor is obsolete and will be removed in a future version.")] public RazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions optionsAccessor, - RazorProject razorProject, ILoggerFactory loggerFactory, - DiagnosticSource diagnosticSource) + DiagnosticListener diagnosticListener) { _options = optionsAccessor.Value; @@ -79,28 +73,10 @@ namespace Microsoft.AspNetCore.Mvc.Razor _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger(); - _razorFileSystem = razorProject; - _diagnosticSource = diagnosticSource; + _diagnosticListener = diagnosticListener; ViewLookupCache = new MemoryCache(new MemoryCacheOptions()); } - /// - /// Initializes a new instance of the RazorViewEngine - /// - public RazorViewEngine( - IRazorPageFactoryProvider pageFactory, - IRazorPageActivator pageActivator, - HtmlEncoder htmlEncoder, - IOptions optionsAccessor, - RazorProjectFileSystem razorFileSystem, - ILoggerFactory loggerFactory, - DiagnosticSource diagnosticSource) -#pragma warning disable CS0618 // Type or member is obsolete - : this (pageFactory, pageActivator, htmlEncoder, optionsAccessor, (RazorProject)razorFileSystem, loggerFactory, diagnosticSource) -#pragma warning restore CS0618 // Type or member is obsolete - { - } - /// /// A cache for results of view lookups. /// @@ -440,10 +416,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor var viewStartPages = isMainPage ? GetViewStartPages(viewDescriptor.RelativePath, expirationTokens) : Array.Empty(); - if (viewDescriptor.IsPrecompiled) - { - _logger.PrecompiledViewFound(relativePath); - } return new ViewLocationCacheResult( new ViewLocationCacheItem(factoryResult.RazorPageFactory, relativePath), @@ -459,9 +431,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor { var viewStartPages = new List(); - foreach (var viewStartProjectItem in _razorFileSystem.FindHierarchicalItems(path, ViewStartFileName)) + foreach (var filePath in RazorFileHierarchy.GetViewStartPaths(path)) { - var result = _pageFactory.CreateFactory(viewStartProjectItem.FilePath); + var result = _pageFactory.CreateFactory(filePath); var viewDescriptor = result.ViewDescriptor; if (viewDescriptor?.ExpirationTokens != null) { @@ -476,7 +448,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor // Populate the viewStartPages list so that _ViewStarts appear in the order the need to be // executed (closest last, furthest first). This is the reverse order in which // ViewHierarchyUtility.GetViewStartLocations returns _ViewStarts. - viewStartPages.Insert(0, new ViewLocationCacheItem(result.RazorPageFactory, viewStartProjectItem.FilePath)); + viewStartPages.Insert(0, new ViewLocationCacheItem(result.RazorPageFactory, filePath)); } } @@ -499,7 +471,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor viewStarts[i] = viewStartItem.PageFactory(); } - var view = new RazorView(this, _pageActivator, viewStarts, page, _htmlEncoder, _diagnosticSource); + var view = new RazorView(this, _pageActivator, viewStarts, page, _htmlEncoder, _diagnosticListener); return ViewEngineResult.Found(viewName, view); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs index 6c6148cb24..d6100bc4e7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptions.cs @@ -1,50 +1,20 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections; using System.Collections.Generic; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.CodeAnalysis; -using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNetCore.Mvc.Razor { /// /// Provides programmatic configuration for the . /// - public class RazorViewEngineOptions : IEnumerable + public class RazorViewEngineOptions { - private readonly ICompatibilitySwitch[] _switches; - private readonly CompatibilitySwitch _allowRecompilingViewsOnFileChange; - private Action _compilationCallback = c => { }; - - public RazorViewEngineOptions() - { - _allowRecompilingViewsOnFileChange = new CompatibilitySwitch(nameof(AllowRecompilingViewsOnFileChange)); - _switches = new[] - { - _allowRecompilingViewsOnFileChange, - }; - } - /// /// Gets a used by the . /// public IList ViewLocationExpanders { get; } = new List(); - /// - /// Gets the sequence of instances used by to - /// locate Razor files. - /// - /// - /// At startup, this is initialized to include an instance of - /// that is rooted at the application root. - /// - public IList FileProviders { get; } = new List(); - /// /// Gets the locations where will search for views. /// @@ -165,81 +135,5 @@ namespace Microsoft.AspNetCore.Mvc.Razor /// /// public IList AreaPageViewLocationFormats { get; } = new List(); - - /// - /// Gets the instances that should be included in Razor compilation, along with - /// those discovered by s. - /// - [Obsolete("This property is obsolete and will be removed in a future version. See https://aka.ms/AA1x4gg for details.")] - public IList AdditionalCompilationReferences { get; } = new List(); - - /// - /// Gets or sets the callback that is used to customize Razor compilation - /// to change compilation settings you can update property. - /// - /// - /// Customizations made here would not reflect in tooling (Intellisense). - /// - [Obsolete("This property is obsolete and will be removed in a future version. See https://aka.ms/AA1x4gg for details.")] - public Action CompilationCallback - { - get => _compilationCallback; - set - { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - _compilationCallback = value; - } - } - - /// - /// Gets or sets a value that determines if Razor files (Razor Views and Razor Pages) are recompiled and updated - /// if files change on disk. - /// - /// When , MVC will use to watch for changes to - /// Razor files in configured instances. - /// - /// - /// - /// The default value is if the version is - /// or earlier. If the version is later and is Development, - /// the default value is . Otherwise, the default value is . - /// - /// - /// - /// This property is associated with a compatibility switch and can provide a different behavior depending on - /// the configured compatibility version for the application. See for - /// guidance and examples of setting the application's compatibility version. - /// - /// - /// Configuring the desired value of the compatibility switch by calling this property's setter will take - /// precedence over the value implied by the application's . - /// - /// - /// If the application's compatibility version is set to or - /// lower then this setting will have the value unless explicitly configured. - /// - /// - /// If the application's compatibility version is set to or - /// higher then this setting will have the value unless - /// is Development or the value is explicitly configured. - /// - /// - public bool AllowRecompilingViewsOnFileChange - { - // Note: When compatibility switches are removed in 3.0, this property should be retained as a regular boolean property. - get => _allowRecompilingViewsOnFileChange.Value; - set => _allowRecompilingViewsOnFileChange.Value = value; - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)_switches).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator(); } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptionsSetup.cs index 6747d87726..d6ffc66da3 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/RazorViewEngineOptionsSetup.cs @@ -2,45 +2,20 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Mvc.Razor { - internal class RazorViewEngineOptionsSetup : - ConfigureCompatibilityOptions, - IConfigureOptions + internal class RazorViewEngineOptionsSetup : IConfigureOptions { private readonly IHostingEnvironment _hostingEnvironment; - public RazorViewEngineOptionsSetup( - IHostingEnvironment hostingEnvironment, - ILoggerFactory loggerFactory, - IOptions compatibilityOptions) - : base(loggerFactory, compatibilityOptions) + public RazorViewEngineOptionsSetup(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); } - protected override IReadOnlyDictionary DefaultValues - { - get - { - var values = new Dictionary(); - if (Version < CompatibilityVersion.Version_2_2) - { - // Default to true in 2.1 or earlier. In 2.2, we have to conditionally enable this - // and consequently this switch has no default value. - values[nameof(RazorViewEngineOptions.AllowRecompilingViewsOnFileChange)] = true; - } - - return values; - } - } - public void Configure(RazorViewEngineOptions options) { if (options == null) @@ -48,22 +23,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor throw new ArgumentNullException(nameof(options)); } - if (_hostingEnvironment.ContentRootFileProvider != null) - { - options.FileProviders.Add(_hostingEnvironment.ContentRootFileProvider); - } - options.ViewLocationFormats.Add("/Views/{1}/{0}" + RazorViewEngine.ViewExtension); options.ViewLocationFormats.Add("/Views/Shared/{0}" + RazorViewEngine.ViewExtension); options.AreaViewLocationFormats.Add("/Areas/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension); options.AreaViewLocationFormats.Add("/Areas/{2}/Views/Shared/{0}" + RazorViewEngine.ViewExtension); options.AreaViewLocationFormats.Add("/Views/Shared/{0}" + RazorViewEngine.ViewExtension); - - if (_hostingEnvironment.IsDevelopment()) - { - options.AllowRecompilingViewsOnFileChange = true; - } } } } \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ServiceBasedTagHelperActivator.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ServiceBasedTagHelperActivator.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ServiceBasedTagHelperActivator.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ServiceBasedTagHelperActivator.cs index d5ba1e6409..142efbe256 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ServiceBasedTagHelperActivator.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ServiceBasedTagHelperActivator.cs @@ -6,13 +6,13 @@ using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { /// /// A that retrieves tag helpers as services from the request's /// . /// - public class ServiceBasedTagHelperActivator : ITagHelperActivator + internal class ServiceBasedTagHelperActivator : ITagHelperActivator { /// public TTagHelper Create(ViewContext context) where TTagHelper : ITagHelper diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelperComponentManager.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/TagHelperComponentManager.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelperComponentManager.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/TagHelperComponentManager.cs index 38dde4f941..bdbaba846d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/TagHelperComponentManager.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/TagHelperComponentManager.cs @@ -6,12 +6,12 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Razor.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { /// /// The default implementation of the . /// - public class TagHelperComponentManager : ITagHelperComponentManager + internal class TagHelperComponentManager : ITagHelperComponentManager { /// /// Creates a new . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs index ddf68268bd..14f11998c9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperComponentTagHelper.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheItem.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheItem.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheItem.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheItem.cs index 64333eb02f..7ba1140bc8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheItem.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheItem.cs @@ -3,12 +3,12 @@ using System; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { /// /// An item in . /// - public readonly struct ViewLocationCacheItem + internal readonly struct ViewLocationCacheItem { /// /// Initializes a new instance of . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheKey.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheKey.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheKey.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheKey.cs index 00f3d3c8ec..2640110dd5 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheKey.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheKey.cs @@ -5,12 +5,12 @@ using System; using System.Collections.Generic; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { /// /// Key for entries in . /// - public readonly struct ViewLocationCacheKey : IEquatable + internal readonly struct ViewLocationCacheKey : IEquatable { /// /// Initializes a new instance of . @@ -111,8 +111,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal foreach (var item in ViewLocationExpanderValues) { - string yValue; - if (!y.ViewLocationExpanderValues.TryGetValue(item.Key, out yValue) || + if (!y.ViewLocationExpanderValues.TryGetValue(item.Key, out var yValue) || !string.Equals(item.Value, yValue, StringComparison.Ordinal)) { return false; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheResult.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheResult.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheResult.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheResult.cs index c703bcaf19..2b72934aa3 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewLocationCacheResult.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewLocationCacheResult.cs @@ -4,12 +4,12 @@ using System; using System.Collections.Generic; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { /// /// Result of view location cache lookup. /// - public class ViewLocationCacheResult + internal class ViewLocationCacheResult { /// /// Initializes a new instance of diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewPath.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewPath.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewPath.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewPath.cs index 813493ee76..640dc69432 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/Internal/ViewPath.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/ViewPath.cs @@ -3,9 +3,9 @@ using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.Razor.Internal +namespace Microsoft.AspNetCore.Mvc.Razor { - public static class ViewPath + internal static class ViewPath { public static string NormalizePath(string path) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/breakingchanges.netcore.json b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/breakingchanges.netcore.json new file mode 100644 index 0000000000..c238459693 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.Razor/breakingchanges.netcore.json @@ -0,0 +1,67 @@ +[ + { + "TypeId": "public abstract class Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorReferenceManager", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException : System.Exception, Microsoft.AspNetCore.Diagnostics.ICompilationException", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeature", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider : Microsoft.AspNetCore.Mvc.ApplicationParts.IApplicationFeatureProvider", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.Compilation.RoslynCompilationContext", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine : Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine", + "MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider pageFactory, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator pageActivator, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, Microsoft.Extensions.Options.IOptions optionsAccessor, Microsoft.AspNetCore.Razor.Language.RazorProject razorProject, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Diagnostics.DiagnosticSource diagnosticSource)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine : Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine", + "MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider pageFactory, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator pageActivator, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, Microsoft.Extensions.Options.IOptions optionsAccessor, Microsoft.AspNetCore.Razor.Language.RazorProjectFileSystem razorFileSystem, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Diagnostics.DiagnosticSource diagnosticSource)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorView : Microsoft.AspNetCore.Mvc.ViewEngines.IView", + "MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine viewEngine, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator pageActivator, System.Collections.Generic.IReadOnlyList viewStartPages, Microsoft.AspNetCore.Mvc.Razor.IRazorPage razorPage, System.Text.Encodings.Web.HtmlEncoder htmlEncoder, System.Diagnostics.DiagnosticSource diagnosticSource)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions", + "MemberId": "public System.Action get_CompilationCallback()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions", + "MemberId": "public System.Collections.Generic.IList get_AdditionalCompilationReferences()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions", + "MemberId": "public System.Void set_CompilationCallback(System.Action value)", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions", + "MemberId": "public System.Collections.Generic.IList get_FileProviders()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.Compilation.CompiledViewDescriptor", + "MemberId": "public System.Boolean get_IsPrecompiled()", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.Razor.Compilation.CompiledViewDescriptor", + "MemberId": "public System.Void set_IsPrecompiled(System.Boolean value)", + "Kind": "Removal" + } +] \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/AuthorizationPageApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/AuthorizationPageApplicationModelProvider.cs similarity index 86% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/AuthorizationPageApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/AuthorizationPageApplicationModelProvider.cs index ad047c1ede..78fc43500e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/AuthorizationPageApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/AuthorizationPageApplicationModelProvider.cs @@ -4,13 +4,11 @@ using System; using System.Linq; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Authorization; -using Microsoft.AspNetCore.Mvc.Internal; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { - public class AuthorizationPageApplicationModelProvider : IPageApplicationModelProvider + internal class AuthorizationPageApplicationModelProvider : IPageApplicationModelProvider { private readonly IAuthorizationPolicyProvider _policyProvider; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/AutoValidateAntiforgeryPageApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/AutoValidateAntiforgeryPageApplicationModelProvider.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/AutoValidateAntiforgeryPageApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/AutoValidateAntiforgeryPageApplicationModelProvider.cs index 5503ba5d03..b4fca876d8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/AutoValidateAntiforgeryPageApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/AutoValidateAntiforgeryPageApplicationModelProvider.cs @@ -6,7 +6,7 @@ using System.Linq; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.ViewFeatures; -namespace Microsoft.AspNetCore.Mvc.RazorPages +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { internal class AutoValidateAntiforgeryPageApplicationModelProvider : IPageApplicationModelProvider { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageActionDescriptorBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageActionDescriptorBuilder.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageActionDescriptorBuilder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageActionDescriptorBuilder.cs index 41055bf878..96f7b895af 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageActionDescriptorBuilder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageActionDescriptorBuilder.cs @@ -4,16 +4,16 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { /// /// Constructs a from an . /// - public static class CompiledPageActionDescriptorBuilder + internal static class CompiledPageActionDescriptorBuilder { /// /// Creates a from the specified . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageRouteModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageRouteModelProvider.cs similarity index 80% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageRouteModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageRouteModelProvider.cs index 544521e5a7..7471af285f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageRouteModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/CompiledPageRouteModelProvider.cs @@ -4,38 +4,32 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor.Compilation; -using Microsoft.AspNetCore.Mvc.Razor.Extensions; -using Microsoft.AspNetCore.Mvc.Razor.Internal; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.AspNetCore.Razor.Hosting; -using Microsoft.AspNetCore.Razor.Language; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { - public class CompiledPageRouteModelProvider : IPageRouteModelProvider + internal class CompiledPageRouteModelProvider : IPageRouteModelProvider { + private static readonly string RazorPageDocumentKind = "mvc.1.0.razor-page"; + private static readonly string RouteTemplateKey = "RouteTemplate"; private readonly ApplicationPartManager _applicationManager; private readonly RazorPagesOptions _pagesOptions; - private readonly RazorProjectEngine _razorProjectEngine; - private readonly ILogger _logger; private readonly PageRouteModelFactory _routeModelFactory; public CompiledPageRouteModelProvider( ApplicationPartManager applicationManager, IOptions pagesOptionsAccessor, - RazorProjectEngine razorProjectEngine, ILogger logger) { _applicationManager = applicationManager ?? throw new ArgumentNullException(nameof(applicationManager)); _pagesOptions = pagesOptionsAccessor?.Value ?? throw new ArgumentNullException(nameof(pagesOptionsAccessor)); - _razorProjectEngine = razorProjectEngine ?? throw new ArgumentNullException(nameof(razorProjectEngine)); - _logger = logger ?? throw new ArgumentNullException(nameof(razorProjectEngine)); - _routeModelFactory = new PageRouteModelFactory(_pagesOptions, _logger); + _routeModelFactory = new PageRouteModelFactory(_pagesOptions, logger); } public int Order => -1000; @@ -76,11 +70,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal continue; } - if (!viewDescriptor.IsPrecompiled) - { - continue; - } - if (IsRazorPage(viewDescriptor)) { yield return viewDescriptor; @@ -91,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal { if (viewDescriptor.Item != null) { - return viewDescriptor.Item.Kind == RazorPageDocumentClassifierPass.RazorPageDocumentKind; + return viewDescriptor.Item.Kind == RazorPageDocumentKind; } else if (viewDescriptor.ViewAttribute != null) { @@ -120,12 +109,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal var areaRootDirectory = "/Areas/"; foreach (var viewDescriptor in GetViewDescriptors(_applicationManager)) { - if (viewDescriptor.Item != null && !ChecksumValidator.IsItemValid(_razorProjectEngine.FileSystem, viewDescriptor.Item)) - { - // If we get here, this compiled Page has different local content, so ignore it. - continue; - } - var relativePath = viewDescriptor.RelativePath; var routeTemplate = GetRouteTemplate(viewDescriptor); PageRouteModel routeModel = null; @@ -159,7 +142,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal { return viewDescriptor.Item.Metadata .OfType() - .FirstOrDefault(f => f.Key == RazorPageDocumentClassifierPass.RouteTemplateKey) + .FirstOrDefault(f => f.Key == RouteTemplateKey) ?.Value; } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/DefaultPageApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/DefaultPageApplicationModelProvider.cs index b486d40e8c..8e6322984b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/DefaultPageApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/DefaultPageApplicationModelProvider.cs @@ -9,7 +9,6 @@ using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; -using Microsoft.AspNetCore.Mvc.RazorPages.Internal; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Options; using Resources = Microsoft.AspNetCore.Mvc.RazorPages.Resources; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageRouteMetadata.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteMetadata.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageRouteMetadata.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteMetadata.cs index ec5390ea98..0ababdcddc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageRouteMetadata.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteMetadata.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { // This is used to store the uncombined parts of the final page route internal class PageRouteMetadata diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModel.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModel.cs index a150977094..6c543a6b6c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModel.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModel.cs @@ -55,6 +55,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels RelativePath = other.RelativePath; ViewEnginePath = other.ViewEnginePath; AreaName = other.AreaName; + RouteParameterTransformer = other.RouteParameterTransformer; Properties = new Dictionary(other.Properties); Selectors = new List(other.Selectors.Select(m => new SelectorModel(m))); @@ -113,5 +114,17 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels /// /// public IDictionary RouteValues { get; } + + /// + /// Gets or sets an that will be used to transform + /// built-in route parameters such as action, controller, and area as well as + /// additional parameters specified by into static segments in the route template. + /// + /// + /// + /// This feature only applies when using endpoint routing. + /// + /// + public IOutboundParameterTransformer RouteParameterTransformer { get; set; } } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageRouteModelFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModelFactory.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageRouteModelFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModelFactory.cs index d6699015be..603a0225dc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageRouteModelFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModelFactory.cs @@ -4,12 +4,12 @@ using System; using System.Diagnostics; using System.IO; -using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { internal class PageRouteModelFactory { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteTransformerConvention.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteTransformerConvention.cs index df47d3b7c2..14903649a9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteTransformerConvention.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteTransformerConvention.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationModels { if (ShouldApply(model)) { - model.Properties[typeof(IOutboundParameterTransformer)] = _parameterTransformer; + model.RouteParameterTransformer = _parameterTransformer; } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ResponseCacheFilterApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/ResponseCacheFilterApplicationModelProvider.cs similarity index 84% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ResponseCacheFilterApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/ResponseCacheFilterApplicationModelProvider.cs index 27a8a7cb9b..09122c103a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ResponseCacheFilterApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/ResponseCacheFilterApplicationModelProvider.cs @@ -3,13 +3,13 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { - public class ResponseCacheFilterApplicationModelProvider : IPageApplicationModelProvider + internal class ResponseCacheFilterApplicationModelProvider : IPageApplicationModelProvider { private readonly MvcOptions _mvcOptions; private readonly ILoggerFactory _loggerFactory; @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal foreach (var attribute in responseCacheAttributes) { var cacheProfile = attribute.GetCacheProfile(_mvcOptions); - context.PageApplicationModel.Filters.Add(new ResponseCacheFilter(cacheProfile, _loggerFactory)); + context.PageApplicationModel.Filters.Add(new PageResponseCacheFilter(cacheProfile, _loggerFactory)); } } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/TempDataFilterPageApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/TempDataFilterPageApplicationModelProvider.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/TempDataFilterPageApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/TempDataFilterPageApplicationModelProvider.cs index 411c13c608..62f0878a21 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/TempDataFilterPageApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/TempDataFilterPageApplicationModelProvider.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.RazorPages +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { internal class TempDataFilterPageApplicationModelProvider : IPageApplicationModelProvider { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ViewDataAttributePageApplicationModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/ViewDataAttributePageApplicationModelProvider.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ViewDataAttributePageApplicationModelProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/ViewDataAttributePageApplicationModelProvider.cs index cdfbe11f0c..c0e12870b7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ViewDataAttributePageApplicationModelProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/ViewDataAttributePageApplicationModelProvider.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.RazorPages.Internal; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; -namespace Microsoft.AspNetCore.Mvc.RazorPages +namespace Microsoft.AspNetCore.Mvc.ApplicationModels { internal class ViewDataAttributePageApplicationModelProvider : IPageApplicationModelProvider { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Builder/RazorPagesEndpointRouteBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Builder/RazorPagesEndpointRouteBuilderExtensions.cs new file mode 100644 index 0000000000..677a426f34 --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Builder/RazorPagesEndpointRouteBuilderExtensions.cs @@ -0,0 +1,42 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Routing; +using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Builder +{ + public static class RazorPagesEndpointRouteBuilderExtensions + { + public static IEndpointConventionBuilder MapRazorPages( + this IEndpointRouteBuilder routeBuilder, + string basePath = null) + { + var mvcEndpointDataSource = routeBuilder.DataSources.OfType().FirstOrDefault(); + + if (mvcEndpointDataSource == null) + { + mvcEndpointDataSource = routeBuilder.ServiceProvider.GetRequiredService(); + routeBuilder.DataSources.Add(mvcEndpointDataSource); + } + + var conventionBuilder = new DefaultEndpointConventionBuilder(); + + mvcEndpointDataSource.AttributeRoutingConventionResolvers.Add(actionDescriptor => + { + if (actionDescriptor is PageActionDescriptor pageActionDescriptor) + { + // TODO: Filter pages by path + return conventionBuilder; + } + + return null; + }); + + return conventionBuilder; + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/DependencyInjection/MvcRazorPagesMvcCoreBuilderExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/DependencyInjection/MvcRazorPagesMvcCoreBuilderExtensions.cs index 2f17cfbbca..4de29ac563 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/DependencyInjection/MvcRazorPagesMvcCoreBuilderExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/DependencyInjection/MvcRazorPagesMvcCoreBuilderExtensions.cs @@ -4,11 +4,11 @@ using System; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ApplicationModels; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; -using Microsoft.AspNetCore.Mvc.RazorPages.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using Resources = Microsoft.AspNetCore.Mvc.RazorPages.Resources; @@ -88,9 +88,6 @@ namespace Microsoft.Extensions.DependencyInjection // Action description and invocation services.TryAddEnumerable( ServiceDescriptor.Singleton()); - services.TryAddSingleton(); - services.TryAddEnumerable( - ServiceDescriptor.Singleton()); services.TryAddEnumerable( ServiceDescriptor.Singleton()); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/RazorPagesRazorViewEngineOptionsSetup.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/DependencyInjection/RazorPagesRazorViewEngineOptionsSetup.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/RazorPagesRazorViewEngineOptionsSetup.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/DependencyInjection/RazorPagesRazorViewEngineOptionsSetup.cs index a0d19edf2f..a39591397e 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/RazorPagesRazorViewEngineOptionsSetup.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/DependencyInjection/RazorPagesRazorViewEngineOptionsSetup.cs @@ -4,12 +4,13 @@ using System; using System.Diagnostics; using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.Extensions.DependencyInjection { - public class RazorPagesRazorViewEngineOptionsSetup : IConfigureOptions + internal class RazorPagesRazorViewEngineOptionsSetup : IConfigureOptions { private readonly RazorPagesOptions _pagesOptions; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerPageFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerPageFilter.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerPageFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerPageFilter.cs index 662fa6113a..4e491eef04 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerPageFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerPageFilter.cs @@ -3,11 +3,11 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.RazorPages; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public class PageHandlerPageFilter : IAsyncPageFilter, IOrderedFilter + internal class PageHandlerPageFilter : IAsyncPageFilter, IOrderedFilter { /// /// Filters on handlers run furthest from the action. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerResultFIlter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerResultFIlter.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerResultFIlter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerResultFIlter.cs index 9d0b3dcd09..c804aeb2d3 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerResultFIlter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageHandlerResultFIlter.cs @@ -3,11 +3,11 @@ using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.RazorPages; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { - public class PageHandlerResultFilter : IAsyncResultFilter, IOrderedFilter + internal class PageHandlerResultFilter : IAsyncResultFilter, IOrderedFilter { /// /// Filters on handlers run furthest from the action. diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ResponseCacheFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageResponseCacheFilter.cs similarity index 88% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ResponseCacheFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageResponseCacheFilter.cs index 6fde160028..989183e491 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ResponseCacheFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageResponseCacheFilter.cs @@ -2,27 +2,26 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.Filters { /// /// A which sets the appropriate headers related to response caching. /// - public class ResponseCacheFilter : IPageFilter, IResponseCacheFilter + internal class PageResponseCacheFilter : IPageFilter, IResponseCacheFilter { private readonly ResponseCacheFilterExecutor _executor; private readonly ILogger _logger; /// - /// Creates a new instance of + /// Creates a new instance of /// /// The profile which contains the settings for - /// . + /// . /// The . - public ResponseCacheFilter(CacheProfile cacheProfile, ILoggerFactory loggerFactory) + public PageResponseCacheFilter(CacheProfile cacheProfile, ILoggerFactory loggerFactory) { _executor = new ResponseCacheFilterExecutor(cacheProfile); _logger = loggerFactory.CreateLogger(GetType()); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageSaveTempDataPropertyFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageSaveTempDataPropertyFilter.cs similarity index 86% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageSaveTempDataPropertyFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageSaveTempDataPropertyFilter.cs index e3f3355fde..3fc0b2b761 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageSaveTempDataPropertyFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageSaveTempDataPropertyFilter.cs @@ -1,11 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; -namespace Microsoft.AspNetCore.Mvc.RazorPages +namespace Microsoft.AspNetCore.Mvc.Filters { internal class PageSaveTempDataPropertyFilter : SaveTempDataPropertyFilterBase, IPageFilter { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageSaveTempDataPropertyFilterFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageSaveTempDataPropertyFilterFactory.cs similarity index 87% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageSaveTempDataPropertyFilterFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageSaveTempDataPropertyFilterFactory.cs index b50ce6b2a9..0bbc255240 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageSaveTempDataPropertyFilterFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageSaveTempDataPropertyFilterFactory.cs @@ -3,15 +3,13 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; using Microsoft.Extensions.DependencyInjection; -namespace Microsoft.AspNetCore.Mvc.RazorPages +namespace Microsoft.AspNetCore.Mvc.Filters { internal class PageSaveTempDataPropertyFilterFactory : IFilterFactory { - public PageSaveTempDataPropertyFilterFactory(IReadOnlyList properties) { Properties = properties; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageViewDataAttributeFilter.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageViewDataAttributeFilter.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageViewDataAttributeFilter.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageViewDataAttributeFilter.cs index 1199f1a91e..98b353b237 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageViewDataAttributeFilter.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageViewDataAttributeFilter.cs @@ -2,11 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; -namespace Microsoft.AspNetCore.Mvc.RazorPages +namespace Microsoft.AspNetCore.Mvc.Filters { internal class PageViewDataAttributeFilter : IPageFilter, IViewDataValuesProviderFeature { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageViewDataAttributeFilterFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageViewDataAttributeFilterFactory.cs similarity index 85% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageViewDataAttributeFilterFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageViewDataAttributeFilterFactory.cs index e75f518aec..42cdda0f04 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageViewDataAttributeFilterFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Filters/PageViewDataAttributeFilterFactory.cs @@ -3,10 +3,9 @@ using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; -namespace Microsoft.AspNetCore.Mvc.RazorPages +namespace Microsoft.AspNetCore.Mvc.Filters { internal class PageViewDataAttributeFilterFactory : IFilterFactory { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageActivatorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageActivatorProvider.cs index f0ec8404a9..3d5c9ac452 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageActivatorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageActivatorProvider.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure /// /// that uses type activation to create Pages. /// - public class DefaultPageActivatorProvider : IPageActivatorProvider + internal class DefaultPageActivatorProvider : IPageActivatorProvider { private readonly Action _disposer = Dispose; /// - public virtual Func CreateActivator(CompiledPageActionDescriptor actionDescriptor) + public Func CreateActivator(CompiledPageActionDescriptor actionDescriptor) { if (actionDescriptor == null) { @@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure return CreatePageFactory(pageTypeInfo); } - public virtual Action CreateReleaser(CompiledPageActionDescriptor actionDescriptor) + public Action CreateReleaser(CompiledPageActionDescriptor actionDescriptor) { if (actionDescriptor == null) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageArgumentBinder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageArgumentBinder.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageArgumentBinder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageArgumentBinder.cs index 9fd638c10c..acc6b2f001 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageArgumentBinder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageArgumentBinder.cs @@ -5,12 +5,11 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { #pragma warning disable CS0618 // Type or member is obsolete - public class DefaultPageArgumentBinder : PageArgumentBinder + internal class DefaultPageArgumentBinder : PageArgumentBinder #pragma warning restore CS0618 // Type or member is obsolete { private readonly ParameterBinder _parameterBinder; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageFactoryProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageFactoryProvider.cs index 709921ab28..607586c7cc 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageFactoryProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageFactoryProvider.cs @@ -6,14 +6,14 @@ using System.Diagnostics; using System.Reflection; using System.Text.Encodings.Web; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.Razor.Internal; +using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.ViewFeatures; namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public class DefaultPageFactoryProvider : IPageFactoryProvider + internal class DefaultPageFactoryProvider : IPageFactoryProvider { private readonly IPageActivatorProvider _pageActivator; private readonly IModelMetadataProvider _modelMetadataProvider; @@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure IModelMetadataProvider metadataProvider, IUrlHelperFactory urlHelperFactory, IJsonHelper jsonHelper, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, HtmlEncoder htmlEncoder, IModelExpressionProvider modelExpressionProvider) { @@ -34,13 +34,13 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { UrlHelperAccessor = context => urlHelperFactory.GetUrlHelper(context), JsonHelperAccessor = context => jsonHelper, - DiagnosticSourceAccessor = context => diagnosticSource, + DiagnosticSourceAccessor = context => diagnosticListener, HtmlEncoderAccessor = context => htmlEncoder, ModelExpressionProviderAccessor = context => modelExpressionProvider, }; } - public virtual Func CreatePageFactory(CompiledPageActionDescriptor actionDescriptor) + public Func CreatePageFactory(CompiledPageActionDescriptor actionDescriptor) { if (!typeof(PageBase).GetTypeInfo().IsAssignableFrom(actionDescriptor.PageTypeInfo)) { @@ -68,7 +68,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure }; } - public virtual Action CreatePageDisposer(CompiledPageActionDescriptor descriptor) + public Action CreatePageDisposer(CompiledPageActionDescriptor descriptor) { if (descriptor == null) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageHandlerMethodSelector.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageHandlerMethodSelector.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageHandlerMethodSelector.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageHandlerMethodSelector.cs index e2a619ca32..325f3e546d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageHandlerMethodSelector.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageHandlerMethodSelector.cs @@ -9,17 +9,12 @@ using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public class DefaultPageHandlerMethodSelector : IPageHandlerMethodSelector + internal class DefaultPageHandlerMethodSelector : IPageHandlerMethodSelector { private const string Handler = "handler"; private readonly IOptions _options; - [Obsolete("This constructor will be removed in a future release. Use the other constructor.")] - public DefaultPageHandlerMethodSelector() - { - } - public DefaultPageHandlerMethodSelector(IOptions options) { if (options == null) diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageLoader.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageLoader.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageLoader.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageLoader.cs index 9bb9390bcc..0534d276ba 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/DefaultPageLoader.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageLoader.cs @@ -11,9 +11,9 @@ using Microsoft.AspNetCore.Mvc.Razor.Compilation; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public class DefaultPageLoader : IPageLoader + internal class DefaultPageLoader : IPageLoader { private readonly IPageApplicationModelProvider[] _applicationModelProviders; private readonly IViewCompilerProvider _viewCompilerProvider; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelActivatorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelActivatorProvider.cs index 2ec04a81ab..e66efcabb0 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelActivatorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelActivatorProvider.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure /// /// that uses type activation to create Razor Page instances. /// - public class DefaultPageModelActivatorProvider : IPageModelActivatorProvider + internal class DefaultPageModelActivatorProvider : IPageModelActivatorProvider { private readonly Action _disposer = Dispose; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelFactoryProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelFactoryProvider.cs index 6821916a4f..4b1eb168e8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelFactoryProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/DefaultPageModelFactoryProvider.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Internal; namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public class DefaultPageModelFactoryProvider : IPageModelFactoryProvider + internal class DefaultPageModelFactoryProvider : IPageModelFactoryProvider { private static readonly Func> _createActivateInfo = CreateActivateInfo; @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure _modelActivator = modelActivator; } - public virtual Func CreateModelFactory(CompiledPageActionDescriptor descriptor) + public Func CreateModelFactory(CompiledPageActionDescriptor descriptor) { if (descriptor == null) { @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure }; } - public virtual Action CreateModelDisposer(CompiledPageActionDescriptor descriptor) + public Action CreateModelDisposer(CompiledPageActionDescriptor descriptor) { if (descriptor == null) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ExecutorFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/ExecutorFactory.cs similarity index 98% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ExecutorFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/ExecutorFactory.cs index 6bea1e9605..99571e68e3 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/ExecutorFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/ExecutorFactory.cs @@ -6,12 +6,11 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.Extensions.Internal; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public static class ExecutorFactory + internal static class ExecutorFactory { public static PageHandlerExecutorDelegate CreateExecutor(HandlerMethodDescriptor handlerDescriptor) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs index 806a032c35..23a449e731 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs @@ -4,15 +4,11 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.Internal; -using Microsoft.AspNetCore.Mvc.RazorPages.Internal; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; -using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure @@ -117,11 +113,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure private static string TransformPageRoute(PageRouteModel model, SelectorModel selectorModel) { - model.Properties.TryGetValue(typeof(IOutboundParameterTransformer), out var transformer); - var pageRouteTransformer = transformer as IOutboundParameterTransformer; - // Transformer not set on page route - if (pageRouteTransformer == null) + if (model.RouteParameterTransformer == null) { return selectorModel.AttributeRouteModel.Template; } @@ -138,7 +131,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure var segments = pageRouteMetadata.PageRoute.Split('/'); for (var i = 0; i < segments.Length; i++) { - segments[i] = pageRouteTransformer.TransformOutbound(segments[i]); + segments[i] = model.RouteParameterTransformer.TransformOutbound(segments[i]); } var transformedPageRoute = string.Join("/", segments); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvoker.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvoker.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvoker.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvoker.cs index 4f91b0346e..8bcdad905b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvoker.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvoker.cs @@ -10,18 +10,15 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public class PageActionInvoker : ResourceInvoker, IActionInvoker + internal class PageActionInvoker : ResourceInvoker, IActionInvoker { private readonly IPageHandlerMethodSelector _selector; private readonly PageContext _pageContext; @@ -42,7 +39,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal public PageActionInvoker( IPageHandlerMethodSelector handlerMethodSelector, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, ILogger logger, IActionResultTypeMapper mapper, PageContext pageContext, @@ -52,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal ITempDataDictionaryFactory tempDataFactory, HtmlHelperOptions htmlHelperOptions) : base( - diagnosticSource, + diagnosticListener, logger, mapper, pageContext, @@ -258,7 +255,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal Debug.Assert(executor != null, "We should always find a executor for a handler"); - _diagnosticSource.BeforeHandlerMethod(_pageContext, handler, _arguments, _instance); + _diagnosticListener.BeforeHandlerMethod(_pageContext, handler, _arguments, _instance); _logger.ExecutingHandlerMethod(_pageContext, handler, arguments); try @@ -268,7 +265,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal } finally { - _diagnosticSource.AfterHandlerMethod(_pageContext, handler, _arguments, _instance, _result); + _diagnosticListener.AfterHandlerMethod(_pageContext, handler, _arguments, _instance, _result); } } @@ -350,7 +347,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal var filter = (IAsyncPageFilter)state; var handlerSelectedContext = _handlerSelectedContext; - _diagnosticSource.BeforeOnPageHandlerSelection(handlerSelectedContext, filter); + _diagnosticListener.BeforeOnPageHandlerSelection(handlerSelectedContext, filter); _logger.BeforeExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IAsyncPageFilter.OnPageHandlerSelectionAsync), @@ -373,7 +370,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal var filter = (IAsyncPageFilter)state; - _diagnosticSource.AfterOnPageHandlerSelection(_handlerSelectedContext, filter); + _diagnosticListener.AfterOnPageHandlerSelection(_handlerSelectedContext, filter); _logger.AfterExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IAsyncPageFilter.OnPageHandlerSelectionAsync), @@ -390,7 +387,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal var filter = (IPageFilter)state; var handlerSelectedContext = _handlerSelectedContext; - _diagnosticSource.BeforeOnPageHandlerSelected(handlerSelectedContext, filter); + _diagnosticListener.BeforeOnPageHandlerSelected(handlerSelectedContext, filter); _logger.BeforeExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IPageFilter.OnPageHandlerSelected), @@ -398,7 +395,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal filter.OnPageHandlerSelected(handlerSelectedContext); - _diagnosticSource.AfterOnPageHandlerSelected(handlerSelectedContext, filter); + _diagnosticListener.AfterOnPageHandlerSelected(handlerSelectedContext, filter); goto case State.PageSelectHandlerNext; } @@ -461,7 +458,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal var filter = (IAsyncPageFilter)state; var handlerExecutingContext = _handlerExecutingContext; - _diagnosticSource.BeforeOnPageHandlerExecution(handlerExecutingContext, filter); + _diagnosticListener.BeforeOnPageHandlerExecution(handlerExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IAsyncPageFilter.OnPageHandlerExecutionAsync), @@ -500,7 +497,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal }; } - _diagnosticSource.AfterOnPageHandlerExecution(_handlerExecutedContext, filter); + _diagnosticListener.AfterOnPageHandlerExecution(_handlerExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IAsyncPageFilter.OnPageHandlerExecutionAsync), @@ -517,7 +514,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal var filter = (IPageFilter)state; var handlerExecutingContext = _handlerExecutingContext; - _diagnosticSource.BeforeOnPageHandlerExecuting(handlerExecutingContext, filter); + _diagnosticListener.BeforeOnPageHandlerExecuting(handlerExecutingContext, filter); _logger.BeforeExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IPageFilter.OnPageHandlerExecuting), @@ -525,7 +522,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal filter.OnPageHandlerExecuting(handlerExecutingContext); - _diagnosticSource.AfterOnPageHandlerExecuting(handlerExecutingContext, filter); + _diagnosticListener.AfterOnPageHandlerExecuting(handlerExecutingContext, filter); _logger.AfterExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IPageFilter.OnPageHandlerExecuting), @@ -568,7 +565,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal var filter = (IPageFilter)state; var handlerExecutedContext = _handlerExecutedContext; - _diagnosticSource.BeforeOnPageHandlerExecuted(handlerExecutedContext, filter); + _diagnosticListener.BeforeOnPageHandlerExecuted(handlerExecutedContext, filter); _logger.BeforeExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IPageFilter.OnPageHandlerExecuted), @@ -576,7 +573,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal filter.OnPageHandlerExecuted(handlerExecutedContext); - _diagnosticSource.AfterOnPageHandlerExecuted(handlerExecutedContext, filter); + _diagnosticListener.AfterOnPageHandlerExecuted(handlerExecutedContext, filter); _logger.AfterExecutingMethodOnFilter( PageLoggerExtensions.PageFilter, nameof(IPageFilter.OnPageHandlerExecuted), diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvokerCacheEntry.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvokerCacheEntry.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvokerCacheEntry.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvokerCacheEntry.cs index f2844d2023..9b964ff661 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvokerCacheEntry.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvokerCacheEntry.cs @@ -10,9 +10,9 @@ using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public class PageActionInvokerCacheEntry + internal class PageActionInvokerCacheEntry { public PageActionInvokerCacheEntry( CompiledPageActionDescriptor actionDescriptor, diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvokerProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvokerProvider.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvokerProvider.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvokerProvider.cs index 007a2f9b14..ffb9f93305 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionInvokerProvider.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionInvokerProvider.cs @@ -9,19 +9,15 @@ using System.Linq; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Razor; -using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; -using Microsoft.AspNetCore.Razor.Language; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public class PageActionInvokerProvider : IActionInvokerProvider + internal class PageActionInvokerProvider : IActionInvokerProvider { private const string ViewStartFileName = "_ViewStart.cshtml"; @@ -39,8 +35,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal private readonly MvcOptions _mvcOptions; private readonly HtmlHelperOptions _htmlHelperOptions; private readonly IPageHandlerMethodSelector _selector; - private readonly RazorProjectFileSystem _razorFileSystem; - private readonly DiagnosticSource _diagnosticSource; + private readonly DiagnosticListener _diagnosticListener; private readonly ILogger _logger; private readonly IActionResultTypeMapper _mapper; private volatile InnerCache _currentCache; @@ -59,8 +54,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal IOptions mvcOptions, IOptions htmlHelperOptions, IPageHandlerMethodSelector selector, - RazorProjectFileSystem razorFileSystem, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, IActionResultTypeMapper mapper) { @@ -78,8 +72,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal _mvcOptions = mvcOptions.Value; _htmlHelperOptions = htmlHelperOptions.Value; _selector = selector; - _razorFileSystem = razorFileSystem; - _diagnosticSource = diagnosticSource; + _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger(); _mapper = mapper; } @@ -159,7 +152,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal return new PageActionInvoker( _selector, - _diagnosticSource, + _diagnosticListener, _logger, _mapper, pageContext, @@ -218,12 +211,9 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal { var viewStartFactories = new List>(); // Always pick up all _ViewStarts, including the ones outside the Pages root. - var viewStartItems = _razorFileSystem.FindHierarchicalItems( - descriptor.RelativePath, - ViewStartFileName); - foreach (var item in viewStartItems) + foreach (var filePath in RazorFileHierarchy.GetViewStartPaths(descriptor.RelativePath)) { - var factoryResult = _razorPageFactoryProvider.CreateFactory(item.FilePath); + var factoryResult = _razorPageFactoryProvider.CreateFactory(filePath); if (factoryResult.Success) { viewStartFactories.Insert(0, factoryResult.RazorPageFactory); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageBinderFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageBinderFactory.cs similarity index 97% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageBinderFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageBinderFactory.cs index 72fd33d754..c29faad2dd 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageBinderFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageBinderFactory.cs @@ -4,11 +4,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { internal static class PageBinderFactory { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageDirectiveFeature.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageDirectiveFeature.cs deleted file mode 100644 index ff09f6abbf..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageDirectiveFeature.cs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Mvc.Razor.Extensions; -using Microsoft.AspNetCore.Mvc.RazorPages.Internal; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Language.Intermediate; -using Microsoft.Extensions.Logging; - -namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure -{ - public static class PageDirectiveFeature - { - private static readonly RazorProjectEngine PageDirectiveEngine = RazorProjectEngine.Create(RazorConfiguration.Default, new EmptyRazorProjectFileSystem(), builder => - { - for (var i = builder.Phases.Count - 1; i >= 0; i--) - { - var phase = builder.Phases[i]; - builder.Phases.RemoveAt(i); - if (phase is IRazorDocumentClassifierPhase) - { - break; - } - } - - RazorExtensions.Register(builder); - builder.Features.Add(new PageDirectiveParserOptionsFeature()); - }); - - public static bool TryGetPageDirective(ILogger logger, RazorProjectItem projectItem, out string template) - { - if (projectItem == null) - { - throw new ArgumentNullException(nameof(projectItem)); - } - - var codeDocument = PageDirectiveEngine.Process(projectItem); - - var documentIRNode = codeDocument.GetDocumentIntermediateNode(); - if (PageDirective.TryGetPageDirective(documentIRNode, out var pageDirective)) - { - if (pageDirective.DirectiveNode is MalformedDirectiveIntermediateNode malformedNode) - { - logger.MalformedPageDirective(projectItem.FilePath, malformedNode.Diagnostics); - } - - template = pageDirective.RouteTemplate; - return true; - } - - template = null; - return false; - } - - private class PageDirectiveParserOptionsFeature : RazorEngineFeatureBase, IConfigureRazorParserOptionsFeature - { - public int Order { get; } - - public void Configure(RazorParserOptionsBuilder options) - { - options.ParseLeadingDirectives = true; - } - } - - private class EmptyRazorProjectFileSystem : RazorProjectFileSystem - { - public override IEnumerable EnumerateItems(string basePath) - { - return Enumerable.Empty(); - } - - public override IEnumerable FindHierarchicalItems(string basePath, string path, string fileName) - { - return Enumerable.Empty(); - } - - public override RazorProjectItem GetItem(string path) - { - return new NotFoundProjectItem(string.Empty, path); - } - - private class NotFoundProjectItem : RazorProjectItem - { - public NotFoundProjectItem(string basePath, string path) - { - BasePath = basePath; - FilePath = path; - } - - /// - public override string BasePath { get; } - - /// - public override string FilePath { get; } - - /// - public override bool Exists => false; - - /// - public override string PhysicalPath => throw new NotSupportedException(); - - /// - public override Stream Read() => throw new NotSupportedException(); - } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerBinderDelegate.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageHandlerBinderDelegate.cs similarity index 57% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerBinderDelegate.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageHandlerBinderDelegate.cs index 7bea47fc51..433f3ccfd8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerBinderDelegate.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageHandlerBinderDelegate.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public delegate Task PageHandlerBinderDelegate(PageContext pageContext, IDictionary arguments); + internal delegate Task PageHandlerBinderDelegate(PageContext pageContext, IDictionary arguments); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerExecutorDelegate.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageHandlerExecutorDelegate.cs similarity index 55% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerExecutorDelegate.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageHandlerExecutorDelegate.cs index e90c24dc75..6c992ad84d 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageHandlerExecutorDelegate.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageHandlerExecutorDelegate.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { - public delegate Task PageHandlerExecutorDelegate(object handler, object[] arguments); + internal delegate Task PageHandlerExecutorDelegate(object handler, object[] arguments); } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageResultExecutor.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageResultExecutor.cs index 967c6fa07d..9ce8e7d6a9 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageResultExecutor.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageResultExecutor.cs @@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { private readonly IRazorViewEngine _razorViewEngine; private readonly IRazorPageActivator _razorPageActivator; - private readonly DiagnosticSource _diagnosticSource; + private readonly DiagnosticListener _diagnosticListener; private readonly HtmlEncoder _htmlEncoder; /// @@ -30,21 +30,21 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure /// The . /// The . /// The . - /// The . + /// The . /// The . public PageResultExecutor( IHttpResponseStreamWriterFactory writerFactory, ICompositeViewEngine compositeViewEngine, IRazorViewEngine razorViewEngine, IRazorPageActivator razorPageActivator, - DiagnosticSource diagnosticSource, + DiagnosticListener diagnosticListener, HtmlEncoder htmlEncoder) - : base(writerFactory, compositeViewEngine, diagnosticSource) + : base(writerFactory, compositeViewEngine, diagnosticListener) { _razorViewEngine = razorViewEngine; _htmlEncoder = htmlEncoder; _razorPageActivator = razorPageActivator; - _diagnosticSource = diagnosticSource; + _diagnosticListener = diagnosticListener; } /// @@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure viewStarts, pageAdapter, _htmlEncoder, - _diagnosticSource) + _diagnosticListener) { OnAfterPageActivated = (page, currentViewContext) => { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/MvcRazorPagesDiagnosticSourceExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/MvcRazorPagesDiagnosticSourceExtensions.cs deleted file mode 100644 index fd7ca7f0bc..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/MvcRazorPagesDiagnosticSourceExtensions.cs +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; - -namespace Microsoft.AspNetCore.Mvc.Internal -{ - public static class MvcRazorPagesDiagnosticSourceExtensions - { - public static void BeforeHandlerMethod( - this DiagnosticSource diagnosticSource, - ActionContext actionContext, - HandlerMethodDescriptor handlerMethodDescriptor, - IDictionary arguments, - object instance) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionContext != null); - Debug.Assert(handlerMethodDescriptor != null); - Debug.Assert(arguments != null); - Debug.Assert(instance != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeHandlerMethod")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeHandlerMethod", - new - { - actionContext = actionContext, - arguments = arguments, - handlerMethodDescriptor = handlerMethodDescriptor, - instance = instance, - }); - } - } - - public static void AfterHandlerMethod( - this DiagnosticSource diagnosticSource, - ActionContext actionContext, - HandlerMethodDescriptor handlerMethodDescriptor, - IDictionary arguments, - object instance, - IActionResult result) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(actionContext != null); - Debug.Assert(handlerMethodDescriptor != null); - Debug.Assert(arguments != null); - Debug.Assert(instance != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterHandlerMethod")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterHandlerMethod", - new - { - actionContext = actionContext, - arguments = arguments, - handlerMethodDescriptor = handlerMethodDescriptor, - instance = instance, - result = result - }); - } - } - - public static void BeforeOnPageHandlerExecution( - this DiagnosticSource diagnosticSource, - PageHandlerExecutingContext handlerExecutionContext, - IAsyncPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerExecutionContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution", - new - { - actionDescriptor = handlerExecutionContext.ActionDescriptor, - handlerExecutionContext = handlerExecutionContext, - filter = filter - }); - } - } - - public static void AfterOnPageHandlerExecution( - this DiagnosticSource diagnosticSource, - PageHandlerExecutedContext handlerExecutedContext, - IAsyncPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution", - new - { - actionDescriptor = handlerExecutedContext.ActionDescriptor, - handlerExecutedContext = handlerExecutedContext, - filter = filter - }); - } - } - - public static void BeforeOnPageHandlerExecuting( - this DiagnosticSource diagnosticSource, - PageHandlerExecutingContext handlerExecutingContext, - IPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting", - new - { - actionDescriptor = handlerExecutingContext.ActionDescriptor, - handlerExecutingContext = handlerExecutingContext, - filter = filter - }); - } - } - - public static void AfterOnPageHandlerExecuting( - this DiagnosticSource diagnosticSource, - PageHandlerExecutingContext handlerExecutingContext, - IPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerExecutingContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting", - new - { - actionDescriptor = handlerExecutingContext.ActionDescriptor, - handlerExecutingContext = handlerExecutingContext, - filter = filter - }); - } - } - - public static void BeforeOnPageHandlerExecuted( - this DiagnosticSource diagnosticSource, - PageHandlerExecutedContext handlerExecutedContext, - IPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted", - new - { - actionDescriptor = handlerExecutedContext.ActionDescriptor, - handlerExecutedContext = handlerExecutedContext, - filter = filter - }); - } - } - - public static void AfterOnPageHandlerExecuted( - this DiagnosticSource diagnosticSource, - PageHandlerExecutedContext handlerExecutedContext, - IPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerExecutedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted", - new - { - actionDescriptor = handlerExecutedContext.ActionDescriptor, - handlerExecutedContext = handlerExecutedContext, - filter = filter - }); - } - } - - public static void BeforeOnPageHandlerSelection( - this DiagnosticSource diagnosticSource, - PageHandlerSelectedContext handlerSelectedContext, - IAsyncPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerSelectedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection", - new - { - actionDescriptor = handlerSelectedContext.ActionDescriptor, - handlerSelectedContext = handlerSelectedContext, - filter = filter - }); - } - } - - public static void AfterOnPageHandlerSelection( - this DiagnosticSource diagnosticSource, - PageHandlerSelectedContext handlerSelectedContext, - IAsyncPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerSelectedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection", - new - { - actionDescriptor = handlerSelectedContext.ActionDescriptor, - handlerSelectedContext = handlerSelectedContext, - filter = filter - }); - } - } - - public static void BeforeOnPageHandlerSelected( - this DiagnosticSource diagnosticSource, - PageHandlerSelectedContext handlerSelectedContext, - IPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerSelectedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected", - new - { - actionDescriptor = handlerSelectedContext.ActionDescriptor, - handlerSelectedContext = handlerSelectedContext, - filter = filter - }); - } - } - - public static void AfterOnPageHandlerSelected( - this DiagnosticSource diagnosticSource, - PageHandlerSelectedContext handlerSelectedContext, - IPageFilter filter) - { - Debug.Assert(diagnosticSource != null); - Debug.Assert(handlerSelectedContext != null); - Debug.Assert(filter != null); - - if (diagnosticSource.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected")) - { - diagnosticSource.Write( - "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected", - new - { - actionDescriptor = handlerSelectedContext.ActionDescriptor, - handlerSelectedContext = handlerSelectedContext, - filter = filter - }); - } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionDescriptorChangeProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionDescriptorChangeProvider.cs deleted file mode 100644 index fadb391b90..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageActionDescriptorChangeProvider.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Diagnostics; -using System.Linq; -using Microsoft.AspNetCore.Mvc.Infrastructure; -using Microsoft.AspNetCore.Mvc.Razor; -using Microsoft.AspNetCore.Mvc.Razor.Internal; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Options; -using Microsoft.Extensions.Primitives; - -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal -{ - public class PageActionDescriptorChangeProvider : IActionDescriptorChangeProvider - { - private readonly IFileProvider _fileProvider; - private readonly string[] _searchPatterns; - private readonly string[] _additionalFilesToTrack; - private readonly bool _watchForChanges; - - public PageActionDescriptorChangeProvider( - RazorTemplateEngine templateEngine, - IRazorViewEngineFileProviderAccessor fileProviderAccessor, - IOptions razorPagesOptions, - IOptions razorViewEngineOptions) - { - if (templateEngine == null) - { - throw new ArgumentNullException(nameof(templateEngine)); - } - - if (fileProviderAccessor == null) - { - throw new ArgumentNullException(nameof(fileProviderAccessor)); - } - - if (razorPagesOptions == null) - { - throw new ArgumentNullException(nameof(razorPagesOptions)); - } - - _watchForChanges = razorViewEngineOptions.Value.AllowRecompilingViewsOnFileChange; - if (!_watchForChanges) - { - // No need to do any additional work if we aren't going to be watching for file changes. - return; - } - - _fileProvider = fileProviderAccessor.FileProvider; - - var rootDirectory = razorPagesOptions.Value.RootDirectory; - Debug.Assert(!string.IsNullOrEmpty(rootDirectory)); - rootDirectory = rootDirectory.TrimEnd('/'); - - // Search pattern that matches all cshtml files under the Pages RootDirectory - var pagesRootSearchPattern = rootDirectory + "/**/*.cshtml"; - - // pagesRootSearchPattern will miss _ViewImports outside the RootDirectory despite these influencing - // compilation. e.g. when RootDirectory = /Dir1/Dir2, the search pattern will ignore changes to - // [/_ViewImports.cshtml, /Dir1/_ViewImports.cshtml]. We need to additionally account for these. - var importFileAtPagesRoot = rootDirectory + "/" + templateEngine.Options.ImportsFileName; - var additionalImportFilePaths = templateEngine.GetImportItems(importFileAtPagesRoot) - .Select(item => item.FilePath); - - if (razorPagesOptions.Value.AllowAreas) - { - // Search pattern that matches all cshtml files under the Pages AreaRootDirectory - var areaRootSearchPattern = "/Areas/**/*.cshtml"; - - var importFileAtAreaPagesRoot = $"/Areas/{templateEngine.Options.ImportsFileName}"; - var importPathsOutsideAreaPagesRoot = templateEngine.GetImportItems(importFileAtAreaPagesRoot) - .Select(item => item.FilePath); - - additionalImportFilePaths = additionalImportFilePaths - .Concat(importPathsOutsideAreaPagesRoot) - .Distinct(StringComparer.OrdinalIgnoreCase); - - _searchPatterns = new[] - { - pagesRootSearchPattern, - areaRootSearchPattern - }; - } - else - { - _searchPatterns = new[] { pagesRootSearchPattern, }; - } - - _additionalFilesToTrack = additionalImportFilePaths.ToArray(); - } - - public IChangeToken GetChangeToken() - { - if (!_watchForChanges) - { - return NullChangeToken.Singleton; - } - - var changeTokens = new IChangeToken[_additionalFilesToTrack.Length + _searchPatterns.Length]; - for (var i = 0; i < _additionalFilesToTrack.Length; i++) - { - changeTokens[i] = _fileProvider.Watch(_additionalFilesToTrack[i]); - } - - for (var i = 0; i < _searchPatterns.Length; i++) - { - var wildcardChangeToken = _fileProvider.Watch(_searchPatterns[i]); - changeTokens[_additionalFilesToTrack.Length + i] = wildcardChangeToken; - } - - return new CompositeChangeToken(changeTokens); - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/RazorProjectPageRouteModelProvider.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/RazorProjectPageRouteModelProvider.cs deleted file mode 100644 index 23384fa9f7..0000000000 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/RazorProjectPageRouteModelProvider.cs +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Linq; -using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; - -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal -{ - public class RazorProjectPageRouteModelProvider : IPageRouteModelProvider - { - private const string AreaRootDirectory = "/Areas"; - private readonly RazorProjectFileSystem _razorFileSystem; - private readonly RazorPagesOptions _pagesOptions; - private readonly PageRouteModelFactory _routeModelFactory; - private readonly ILogger _logger; - - public RazorProjectPageRouteModelProvider( - RazorProjectFileSystem razorFileSystem, - IOptions pagesOptionsAccessor, - ILoggerFactory loggerFactory) - { - _razorFileSystem = razorFileSystem; - _pagesOptions = pagesOptionsAccessor.Value; - _logger = loggerFactory.CreateLogger(); - _routeModelFactory = new PageRouteModelFactory(_pagesOptions, _logger); - } - - /// - /// Ordered to execute after . - /// - public int Order => -1000 + 10; - - public void OnProvidersExecuted(PageRouteModelProviderContext context) - { - } - - public void OnProvidersExecuting(PageRouteModelProviderContext context) - { - // When RootDirectory and AreaRootDirectory overlap, e.g. RootDirectory = /, AreaRootDirectory = /Areas; - // we need to ensure that the page is only route-able via the area route. By adding area routes first, - // we'll ensure non area routes get skipped when it encounters an IsAlreadyRegistered check. - - if (_pagesOptions.AllowAreas) - { - AddAreaPageModels(context); - } - - AddPageModels(context); - } - - private void AddPageModels(PageRouteModelProviderContext context) - { - foreach (var item in _razorFileSystem.EnumerateItems(_pagesOptions.RootDirectory)) - { - var relativePath = item.CombinedPath; - if (context.RouteModels.Any(m => string.Equals(relativePath, m.RelativePath, StringComparison.OrdinalIgnoreCase))) - { - // A route for this file was already registered either by the CompiledPageRouteModel or as an area route. - // by this provider. Skip registering an additional entry. - - // Note: We're comparing duplicates based on root-relative paths. This eliminates a page from being discovered - // by overlapping area and non-area routes where ViewEnginePath would be different. - continue; - } - - if (!PageDirectiveFeature.TryGetPageDirective(_logger, item, out var routeTemplate)) - { - // .cshtml pages without @page are not RazorPages. - continue; - } - - if (_pagesOptions.AllowAreas && relativePath.StartsWith(AreaRootDirectory, StringComparison.OrdinalIgnoreCase)) - { - // Ignore Razor pages that are under the area root directory when AllowAreas is enabled. - // Conforming page paths will be added by AddAreaPageModels. - _logger.UnsupportedAreaPath(relativePath); - continue; - } - - var routeModel = _routeModelFactory.CreateRouteModel(relativePath, routeTemplate); - if (routeModel != null) - { - context.RouteModels.Add(routeModel); - } - } - } - - private void AddAreaPageModels(PageRouteModelProviderContext context) - { - foreach (var item in _razorFileSystem.EnumerateItems(AreaRootDirectory)) - { - var relativePath = item.CombinedPath; - if (context.RouteModels.Any(m => string.Equals(relativePath, m.RelativePath, StringComparison.OrdinalIgnoreCase))) - { - // A route for this file was already registered either by the CompiledPageRouteModel. - // Skip registering an additional entry. - continue; - } - - if (!PageDirectiveFeature.TryGetPageDirective(_logger, item, out var routeTemplate)) - { - // .cshtml pages without @page are not RazorPages. - continue; - } - - var routeModel = _routeModelFactory.CreateAreaRouteModel(relativePath, routeTemplate); - if (routeModel != null) - { - context.RouteModels.Add(routeModel); - } - } - } - } -} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Microsoft.AspNetCore.Mvc.RazorPages.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Microsoft.AspNetCore.Mvc.RazorPages.csproj index 1655f9da77..fef57ee4d1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Microsoft.AspNetCore.Mvc.RazorPages.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Microsoft.AspNetCore.Mvc.RazorPages.csproj @@ -2,7 +2,7 @@ ASP.NET Core MVC Razor Pages. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc;cshtml;razor diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/MvcRazorPagesDiagnosticSourceExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/MvcRazorPagesDiagnosticSourceExtensions.cs new file mode 100644 index 0000000000..5747c9828f --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/MvcRazorPagesDiagnosticSourceExtensions.cs @@ -0,0 +1,397 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; + +namespace Microsoft.AspNetCore.Mvc.RazorPages +{ + internal static class MvcRazorPagesDiagnosticSourceExtensions + { + public static void BeforeHandlerMethod( + this DiagnosticListener diagnosticListener, + ActionContext actionContext, + HandlerMethodDescriptor handlerMethodDescriptor, + IDictionary arguments, + object instance) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionContext != null); + Debug.Assert(handlerMethodDescriptor != null); + Debug.Assert(arguments != null); + Debug.Assert(instance != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeHandlerMethodImpl(diagnosticListener, actionContext, handlerMethodDescriptor, arguments, instance); + } + } + + private static void BeforeHandlerMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, HandlerMethodDescriptor handlerMethodDescriptor, IDictionary arguments, object instance) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeHandlerMethod")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeHandlerMethod", + new + { + actionContext = actionContext, + arguments = arguments, + handlerMethodDescriptor = handlerMethodDescriptor, + instance = instance, + }); + } + } + + public static void AfterHandlerMethod( + this DiagnosticListener diagnosticListener, + ActionContext actionContext, + HandlerMethodDescriptor handlerMethodDescriptor, + IDictionary arguments, + object instance, + IActionResult result) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(actionContext != null); + Debug.Assert(handlerMethodDescriptor != null); + Debug.Assert(arguments != null); + Debug.Assert(instance != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterHandlerMethodImpl(diagnosticListener, actionContext, handlerMethodDescriptor, arguments, instance, result); + } + } + + private static void AfterHandlerMethodImpl(DiagnosticListener diagnosticListener, ActionContext actionContext, HandlerMethodDescriptor handlerMethodDescriptor, IDictionary arguments, object instance, IActionResult result) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterHandlerMethod")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterHandlerMethod", + new + { + actionContext = actionContext, + arguments = arguments, + handlerMethodDescriptor = handlerMethodDescriptor, + instance = instance, + result = result + }); + } + } + + public static void BeforeOnPageHandlerExecution( + this DiagnosticListener diagnosticListener, + PageHandlerExecutingContext handlerExecutionContext, + IAsyncPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerExecutionContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnPageHandlerExecutionImpl(diagnosticListener, handlerExecutionContext, filter); + } + } + + private static void BeforeOnPageHandlerExecutionImpl(DiagnosticListener diagnosticListener, PageHandlerExecutingContext handlerExecutionContext, IAsyncPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecution", + new + { + actionDescriptor = handlerExecutionContext.ActionDescriptor, + handlerExecutionContext = handlerExecutionContext, + filter = filter + }); + } + } + + public static void AfterOnPageHandlerExecution( + this DiagnosticListener diagnosticListener, + PageHandlerExecutedContext handlerExecutedContext, + IAsyncPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnPageHandlerExecutionImpl(diagnosticListener, handlerExecutedContext, filter); + } + } + + private static void AfterOnPageHandlerExecutionImpl(DiagnosticListener diagnosticListener, PageHandlerExecutedContext handlerExecutedContext, IAsyncPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecution", + new + { + actionDescriptor = handlerExecutedContext.ActionDescriptor, + handlerExecutedContext = handlerExecutedContext, + filter = filter + }); + } + } + + public static void BeforeOnPageHandlerExecuting( + this DiagnosticListener diagnosticListener, + PageHandlerExecutingContext handlerExecutingContext, + IPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnPageHandlerExecutingImpl(diagnosticListener, handlerExecutingContext, filter); + } + } + + private static void BeforeOnPageHandlerExecutingImpl(DiagnosticListener diagnosticListener, PageHandlerExecutingContext handlerExecutingContext, IPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuting", + new + { + actionDescriptor = handlerExecutingContext.ActionDescriptor, + handlerExecutingContext = handlerExecutingContext, + filter = filter + }); + } + } + + public static void AfterOnPageHandlerExecuting( + this DiagnosticListener diagnosticListener, + PageHandlerExecutingContext handlerExecutingContext, + IPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerExecutingContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnPageHandlerExecutingImpl(diagnosticListener, handlerExecutingContext, filter); + } + } + + private static void AfterOnPageHandlerExecutingImpl(DiagnosticListener diagnosticListener, PageHandlerExecutingContext handlerExecutingContext, IPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuting", + new + { + actionDescriptor = handlerExecutingContext.ActionDescriptor, + handlerExecutingContext = handlerExecutingContext, + filter = filter + }); + } + } + + public static void BeforeOnPageHandlerExecuted( + this DiagnosticListener diagnosticListener, + PageHandlerExecutedContext handlerExecutedContext, + IPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnPageHandlerExecutedImpl(diagnosticListener, handlerExecutedContext, filter); + } + } + + private static void BeforeOnPageHandlerExecutedImpl(DiagnosticListener diagnosticListener, PageHandlerExecutedContext handlerExecutedContext, IPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerExecuted", + new + { + actionDescriptor = handlerExecutedContext.ActionDescriptor, + handlerExecutedContext = handlerExecutedContext, + filter = filter + }); + } + } + + public static void AfterOnPageHandlerExecuted( + this DiagnosticListener diagnosticListener, + PageHandlerExecutedContext handlerExecutedContext, + IPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerExecutedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnPageHandlerExecutedImpl(diagnosticListener, handlerExecutedContext, filter); + } + } + + private static void AfterOnPageHandlerExecutedImpl(DiagnosticListener diagnosticListener, PageHandlerExecutedContext handlerExecutedContext, IPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerExecuted", + new + { + actionDescriptor = handlerExecutedContext.ActionDescriptor, + handlerExecutedContext = handlerExecutedContext, + filter = filter + }); + } + } + + public static void BeforeOnPageHandlerSelection( + this DiagnosticListener diagnosticListener, + PageHandlerSelectedContext handlerSelectedContext, + IAsyncPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerSelectedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnPageHandlerSelectionImpl(diagnosticListener, handlerSelectedContext, filter); + } + } + + private static void BeforeOnPageHandlerSelectionImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IAsyncPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelection", + new + { + actionDescriptor = handlerSelectedContext.ActionDescriptor, + handlerSelectedContext = handlerSelectedContext, + filter = filter + }); + } + } + + public static void AfterOnPageHandlerSelection( + this DiagnosticListener diagnosticListener, + PageHandlerSelectedContext handlerSelectedContext, + IAsyncPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerSelectedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnPageHandlerSelectionImpl(diagnosticListener, handlerSelectedContext, filter); + } + } + + private static void AfterOnPageHandlerSelectionImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IAsyncPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelection", + new + { + actionDescriptor = handlerSelectedContext.ActionDescriptor, + handlerSelectedContext = handlerSelectedContext, + filter = filter + }); + } + } + + public static void BeforeOnPageHandlerSelected( + this DiagnosticListener diagnosticListener, + PageHandlerSelectedContext handlerSelectedContext, + IPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerSelectedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + BeforeOnPageHandlerSelectedImpl(diagnosticListener, handlerSelectedContext, filter); + } + } + + private static void BeforeOnPageHandlerSelectedImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.BeforeOnPageHandlerSelected", + new + { + actionDescriptor = handlerSelectedContext.ActionDescriptor, + handlerSelectedContext = handlerSelectedContext, + filter = filter + }); + } + } + + public static void AfterOnPageHandlerSelected( + this DiagnosticListener diagnosticListener, + PageHandlerSelectedContext handlerSelectedContext, + IPageFilter filter) + { + Debug.Assert(diagnosticListener != null); + Debug.Assert(handlerSelectedContext != null); + Debug.Assert(filter != null); + + // Inlinable fast-path check if Diagnositcs is enabled + if (diagnosticListener.IsEnabled()) + { + AfterOnPageHandlerSelectedImpl(diagnosticListener, handlerSelectedContext, filter); + } + } + + private static void AfterOnPageHandlerSelectedImpl(DiagnosticListener diagnosticListener, PageHandlerSelectedContext handlerSelectedContext, IPageFilter filter) + { + if (diagnosticListener.IsEnabled("Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected")) + { + diagnosticListener.Write( + "Microsoft.AspNetCore.Mvc.AfterOnPageHandlerSelected", + new + { + actionDescriptor = handlerSelectedContext.ActionDescriptor, + handlerSelectedContext = handlerSelectedContext, + filter = filter + }); + } + } + } +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs index 3dda563ebb..1d43071cf7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageBase.cs @@ -10,7 +10,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Rendering; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageLoggerExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageLoggerExtensions.cs similarity index 91% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageLoggerExtensions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageLoggerExtensions.cs index 1ff89f5512..2407767fc7 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/PageLoggerExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageLoggerExtensions.cs @@ -2,14 +2,12 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; -using Microsoft.AspNetCore.Razor.Language; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal +namespace Microsoft.AspNetCore.Mvc.RazorPages { internal static class PageLoggerExtensions { @@ -151,20 +149,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal _pageFilterShortCircuit(logger, filter, null); } - public static void MalformedPageDirective(this ILogger logger, string filePath, IList diagnostics) - { - if (logger.IsEnabled(LogLevel.Warning)) - { - var messages = new string[diagnostics.Count]; - for (var i = 0; i < diagnostics.Count; i++) - { - messages[i] = diagnostics[i].GetMessage(); - } - - _malformedPageDirective(logger, filePath, messages, null); - } - } - public static void NotMostEffectiveFilter(this ILogger logger, Type policyType) { _notMostEffectiveFilter(logger, policyType, null); diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageModel.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageModel.cs index 17384ca1ce..630084b897 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageModel.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/PageModel.cs @@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.AspNetCore.Mvc.Routing; diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/breakingchanges.netcore.json b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/breakingchanges.netcore.json new file mode 100644 index 0000000000..e2fa5d1d6c --- /dev/null +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.RazorPages/breakingchanges.netcore.json @@ -0,0 +1,31 @@ +[ + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageActivatorProvider : Microsoft.AspNetCore.Mvc.RazorPages.IPageActivatorProvider", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageFactoryProvider : Microsoft.AspNetCore.Mvc.RazorPages.IPageFactoryProvider", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageHandlerMethodSelector : Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.IPageHandlerMethodSelector", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageModelActivatorProvider : Microsoft.AspNetCore.Mvc.RazorPages.IPageModelActivatorProvider", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageModelFactoryProvider : Microsoft.AspNetCore.Mvc.RazorPages.IPageModelFactoryProvider", + "Kind": "Removal" + }, + { + "TypeId": "public class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageResultExecutor : Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor", + "MemberId": "public .ctor(Microsoft.AspNetCore.Mvc.Infrastructure.IHttpResponseStreamWriterFactory writerFactory, Microsoft.AspNetCore.Mvc.ViewEngines.ICompositeViewEngine compositeViewEngine, Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine razorViewEngine, Microsoft.AspNetCore.Mvc.Razor.IRazorPageActivator razorPageActivator, System.Diagnostics.DiagnosticSource diagnosticSource, System.Text.Encodings.Web.HtmlEncoder htmlEncoder)", + "Kind": "Removal" + }, + { + "TypeId": "public static class Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageDirectiveFeature", + "Kind": "Removal" + } +] \ No newline at end of file diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/AttributeMatcher.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/AttributeMatcher.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/AttributeMatcher.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/AttributeMatcher.cs index 5caa08dc5b..309f2aa574 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/AttributeMatcher.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/AttributeMatcher.cs @@ -5,12 +5,12 @@ using System; using System.Collections.Generic; using Microsoft.AspNetCore.Razor.TagHelpers; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { /// /// Methods for determining how an should run based on the attributes that were specified. /// - public static class AttributeMatcher + internal static class AttributeMatcher { /// /// Determines the most effective mode a can run in based on which modes have @@ -73,15 +73,13 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal // Perf: Avoid allocating enumerator for (var i = 0; i < requiredAttributes.Length; i++) { - TagHelperAttribute attribute; - if (!context.AllAttributes.TryGetAttribute(requiredAttributes[i], out attribute)) + if (!context.AllAttributes.TryGetAttribute(requiredAttributes[i], out var attribute)) { // Missing attribute. return true; } - var valueAsString = attribute.Value as string; - if (valueAsString != null && string.IsNullOrEmpty(valueAsString)) + if (attribute.Value is string valueAsString && string.IsNullOrEmpty(valueAsString)) { // Treat attributes with empty values as missing. return true; @@ -91,4 +89,4 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal return false; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs index 7db418f9b4..88c4e0332c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Cache/DistributedCacheTagHelperService.cs @@ -9,7 +9,6 @@ using System.Text; using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; -using Microsoft.AspNetCore.Mvc.TagHelpers.Internal; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Logging; @@ -80,10 +79,8 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache while (content == null) { - Task result; - // Is there any request already processing the value? - if (!_workers.TryGetValue(key, out result)) + if (!_workers.TryGetValue(key, out var result)) { // There is a small race condition here between TryGetValue and TryAdd that might cause the // content to be computed more than once. We don't care about this race as the probability of diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs index de3fc45194..a097528945 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelper.cs @@ -10,8 +10,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.TagHelpers.Cache; -using Microsoft.AspNetCore.Mvc.TagHelpers.Internal; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; +using Microsoft.AspNetCore.Mvc.ViewFeatures.Buffers; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Primitives; @@ -44,9 +43,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers /// used by the . /// The to use. public CacheTagHelper( -#pragma warning disable PUB0001 // Pubternal type in public API CacheTagHelperMemoryCacheFactory factory, -#pragma warning restore PUB0001 HtmlEncoder htmlEncoder) : base(htmlEncoder) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/CacheTagHelperMemoryCacheFactory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelperMemoryCacheFactory.cs similarity index 93% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/CacheTagHelperMemoryCacheFactory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelperMemoryCacheFactory.cs index 7239f80260..6b1ac41fb8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/CacheTagHelperMemoryCacheFactory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CacheTagHelperMemoryCacheFactory.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Options; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { public class CacheTagHelperMemoryCacheFactory { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/CurrentValues.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CurrentValues.cs similarity index 85% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/CurrentValues.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CurrentValues.cs index 6126d91507..8794df7203 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/CurrentValues.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/CurrentValues.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using System.Diagnostics; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { - public class CurrentValues + internal class CurrentValues { public CurrentValues(ICollection values) { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/DependencyInjection/TagHelperExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/DependencyInjection/TagHelperExtensions.cs index 5161244492..e39242536a 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/DependencyInjection/TagHelperExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/DependencyInjection/TagHelperExtensions.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNetCore.Mvc.TagHelpers; using Microsoft.AspNetCore.Mvc.TagHelpers.Cache; -using Microsoft.AspNetCore.Mvc.TagHelpers.Internal; using Microsoft.Extensions.DependencyInjection.Extensions; namespace Microsoft.Extensions.DependencyInjection diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingDirectory.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/FileProviderGlobbingDirectory.cs similarity index 96% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingDirectory.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/FileProviderGlobbingDirectory.cs index c2d0bf6227..5cb63e410f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingDirectory.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/FileProviderGlobbingDirectory.cs @@ -6,9 +6,9 @@ using System.Collections.Generic; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileSystemGlobbing.Abstractions; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { - public class FileProviderGlobbingDirectory : DirectoryInfoBase + internal class FileProviderGlobbingDirectory : DirectoryInfoBase { private const char DirectorySeparatorChar = '/'; private readonly IFileProvider _fileProvider; @@ -96,4 +96,4 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal return new FileProviderGlobbingFile(fileInfo, this); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingFile.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/FileProviderGlobbingFile.cs similarity index 90% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingFile.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/FileProviderGlobbingFile.cs index 2696781c8c..67ccc9e046 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/FileProviderGlobbingFile.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/FileProviderGlobbingFile.cs @@ -5,9 +5,9 @@ using System; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileSystemGlobbing.Abstractions; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { - public class FileProviderGlobbingFile : FileInfoBase + internal class FileProviderGlobbingFile : FileInfoBase { private const char DirectorySeparatorChar = '/'; @@ -34,4 +34,4 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal public override DirectoryInfoBase ParentDirectory { get; } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/GlobbingUrlBuilder.cs similarity index 99% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/GlobbingUrlBuilder.cs index ce891ad84e..82c176bc8b 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/GlobbingUrlBuilder.cs @@ -10,7 +10,7 @@ using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Primitives; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { /// /// Utility methods for 's that support @@ -381,4 +381,4 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal } } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs index 8ea3effdd4..16e7950dba 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/InputTagHelper.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.AspNetCore.Razor.TagHelpers; namespace Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/JavaScriptResources.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/JavaScriptResources.cs similarity index 95% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/JavaScriptResources.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/JavaScriptResources.cs index ad0bdf93a4..394d9de910 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/JavaScriptResources.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/JavaScriptResources.cs @@ -7,12 +7,12 @@ using System.Diagnostics; using System.IO; using System.Reflection; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { /// /// Methods for loading JavaScript from assembly embedded resources. /// - public static class JavaScriptResources + internal static class JavaScriptResources { private static readonly Assembly ResourcesAssembly = typeof(JavaScriptResources).GetTypeInfo().Assembly; @@ -58,4 +58,4 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal return input.Substring(0, input.Length - 2); } } -} \ No newline at end of file +} diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs index d082db1ef6..34d4ef1fa1 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs @@ -12,7 +12,6 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc.Razor.Infrastructure; using Microsoft.AspNetCore.Mvc.Razor.TagHelpers; using Microsoft.AspNetCore.Mvc.Routing; -using Microsoft.AspNetCore.Mvc.TagHelpers.Internal; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Caching.Memory; @@ -241,9 +240,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers protected JavaScriptEncoder JavaScriptEncoder { get; } // Internal for ease of use when testing. -#pragma warning disable PUB0001 // Pubternal type in public API protected internal GlobbingUrlBuilder GlobbingUrlBuilder { get; set; } -#pragma warning restore PUB0001 internal IFileVersionProvider FileVersionProvider { get; private set; } diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Microsoft.AspNetCore.Mvc.TagHelpers.csproj b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Microsoft.AspNetCore.Mvc.TagHelpers.csproj index 5bd518d2f0..082cb972b8 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Microsoft.AspNetCore.Mvc.TagHelpers.csproj +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Microsoft.AspNetCore.Mvc.TagHelpers.csproj @@ -2,7 +2,7 @@ ASP.NET Core MVC default tag helpers. Contains tag helpers for anchor tags, HTML input elements, caching, scripts, links (for CSS), and more. - netstandard2.0 + netcoreapp3.0 $(NoWarn);CS1591 true aspnetcore;aspnetcoremvc;taghelper;taghelpers diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/ModeAttributesOfT.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ModeAttributesOfT.cs similarity index 92% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/ModeAttributesOfT.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ModeAttributesOfT.cs index d5079b7d46..6aafc88d8f 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/ModeAttributesOfT.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/ModeAttributesOfT.cs @@ -1,13 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { /// /// A mapping of a mode to its required attributes. /// /// The type representing the 's mode. - public class ModeAttributes + internal class ModeAttributes { /// /// Initializes a new instance of . diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/MvcTagHelpersLoggerExtensions.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/MvcTagHelpersLoggerExtensions.cs similarity index 94% rename from src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/MvcTagHelpersLoggerExtensions.cs rename to src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/MvcTagHelpersLoggerExtensions.cs index 1943e1bcb8..7a78c67530 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/Internal/MvcTagHelpersLoggerExtensions.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/MvcTagHelpersLoggerExtensions.cs @@ -4,7 +4,7 @@ using System; using Microsoft.Extensions.Logging; -namespace Microsoft.AspNetCore.Mvc.TagHelpers.Internal +namespace Microsoft.AspNetCore.Mvc.TagHelpers { internal static class MvcTagHelperLoggerExtensions { diff --git a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs index 8f2678e968..3cfaf3bb4c 100644 --- a/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs +++ b/src/Mvc/src/Microsoft.AspNetCore.Mvc.TagHelpers/OptionTagHelper.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.AspNetCore.Mvc.TagHelpers.Internal; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; @@ -76,8 +75,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers if (!output.Attributes.ContainsName("selected")) { // Is this