Skip to content

Commit 4986a10

Browse files
committed
Clean up consolidated views APIs
1 parent c19003c commit 4986a10

6 files changed

+48
-106
lines changed

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcViewDocumentClassifierPass.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
99
{
1010
public class MvcViewDocumentClassifierPass : DocumentClassifierPassBase
1111
{
12+
private bool _useConsolidatedMvcViews = false;
13+
1214
public static readonly string MvcViewDocumentKind = "mvc.1.0.view";
1315

1416
protected override string DocumentKind => MvcViewDocumentKind;
1517

1618
protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true;
1719

20+
public MvcViewDocumentClassifierPass(bool useConsolidatedMvcViews = false)
21+
{
22+
_useConsolidatedMvcViews = useConsolidatedMvcViews;
23+
}
24+
1825
protected override void OnDocumentStructureCreated(
1926
RazorCodeDocument codeDocument,
2027
NamespaceDeclarationIntermediateNode @namespace,
@@ -25,7 +32,7 @@ protected override void OnDocumentStructureCreated(
2532

2633
if (!codeDocument.TryComputeNamespace(fallbackToRootNamespace: false, out var namespaceName))
2734
{
28-
@namespace.Content = "AspNetCore";
35+
@namespace.Content = _useConsolidatedMvcViews ? "AspNetCoreGeneratedDocument" : "AspNetCore";
2936
}
3037
else
3138
{
@@ -47,7 +54,15 @@ protected override void OnDocumentStructureCreated(
4754

4855
@class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage<TModel>";
4956
@class.Modifiers.Clear();
50-
@class.Modifiers.Add("public");
57+
if (_useConsolidatedMvcViews)
58+
{
59+
@class.Modifiers.Add("internal");
60+
@class.Modifiers.Add("sealed");
61+
}
62+
else
63+
{
64+
@class.Modifiers.Add("public");
65+
}
5166

5267
method.MethodName = "ExecuteAsync";
5368
method.Modifiers.Clear();
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#nullable enable
2-
Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass
3-
Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.ConsolidatedMvcViewDocumentClassifierPass() -> void
4-
~static readonly Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.MvcViewDocumentKind -> string
2+
*REMOVED*Microsoft.AspNetCore.Mvc.Razor.Extensions.MvcViewDocumentClassifierPass.MvcViewDocumentClassifierPass() -> void
3+
*REMOVED*Microsoft.AspNetCore.Mvc.Razor.Extensions.RazorPageDocumentClassifierPass.RazorPageDocumentClassifierPass() -> void
4+
Microsoft.AspNetCore.Mvc.Razor.Extensions.MvcViewDocumentClassifierPass.MvcViewDocumentClassifierPass(bool useConsolidatedMvcViews = false) -> void
5+
Microsoft.AspNetCore.Mvc.Razor.Extensions.RazorPageDocumentClassifierPass.RazorPageDocumentClassifierPass(bool useConsolidatedMvcViews = false) -> void

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ public static void Register(RazorProjectEngineBuilder builder)
3636
builder.Features.Add(new ModelExpressionPass());
3737
builder.Features.Add(new PagesPropertyInjectionPass());
3838
builder.Features.Add(new ViewComponentTagHelperPass());
39-
builder.Features.Add(new RazorPageDocumentClassifierPass());
39+
4040

4141
if (builder.Configuration.UseConsolidatedMvcViews)
4242
{
43-
builder.Features.Add(new ConsolidatedMvcViewDocumentClassifierPass());
43+
builder.Features.Add(new RazorPageDocumentClassifierPass(useConsolidatedMvcViews: true));
44+
builder.Features.Add(new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true));
4445
}
4546
else
4647
{
47-
builder.Features.Add(new MvcViewDocumentClassifierPass());
48+
builder.Features.Add(new RazorPageDocumentClassifierPass()); builder.Features.Add(new MvcViewDocumentClassifierPass());
4849
}
4950

5051
builder.Features.Add(new MvcImportProjectFeature());

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorPageDocumentClassifierPass.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
1111
{
1212
public class RazorPageDocumentClassifierPass : DocumentClassifierPassBase
1313
{
14+
private bool _useConsolidatedMvcViews = false;
15+
1416
public static readonly string RazorPageDocumentKind = "mvc.1.0.razor-page";
1517
public static readonly string RouteTemplateKey = "RouteTemplate";
1618

19+
public RazorPageDocumentClassifierPass(bool useConsolidatedMvcViews = false)
20+
{
21+
_useConsolidatedMvcViews = useConsolidatedMvcViews;
22+
}
23+
1724
private static readonly RazorProjectEngine LeadingDirectiveParsingEngine = RazorProjectEngine.Create(
1825
RazorConfiguration.Create(RazorLanguageVersion.Version_3_0, "leading-directive-parser", Array.Empty<RazorExtension>()),
1926
RazorProjectFileSystem.Create("/"),
@@ -50,7 +57,7 @@ protected override void OnDocumentStructureCreated(
5057

5158
if (!codeDocument.TryComputeNamespace(fallbackToRootNamespace: false, out var namespaceName))
5259
{
53-
@namespace.Content = "AspNetCore";
60+
@namespace.Content = _useConsolidatedMvcViews ? "AspNetCoreGeneratedDocument" : "AspNetCore";
5461
}
5562
else
5663
{
@@ -71,7 +78,15 @@ protected override void OnDocumentStructureCreated(
7178

7279
@class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page";
7380
@class.Modifiers.Clear();
74-
@class.Modifiers.Add("public");
81+
if (_useConsolidatedMvcViews)
82+
{
83+
@class.Modifiers.Add("internal");
84+
@class.Modifiers.Add("sealed");
85+
}
86+
else
87+
{
88+
@class.Modifiers.Add("public");
89+
}
7590

7691
method.MethodName = "ExecuteAsync";
7792
method.Modifiers.Clear();

src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsDifferentNamespace()
1919

2020
var projectEngine = CreateProjectEngine();
2121
var irDocument = CreateIRDocument(projectEngine, codeDocument);
22-
var pass = new ConsolidatedMvcViewDocumentClassifierPass
22+
var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true)
2323
{
2424
Engine = projectEngine.Engine
2525
};
@@ -42,7 +42,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsClass()
4242

4343
var projectEngine = CreateProjectEngine();
4444
var irDocument = CreateIRDocument(projectEngine, codeDocument);
45-
var pass = new ConsolidatedMvcViewDocumentClassifierPass
45+
var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true)
4646
{
4747
Engine = projectEngine.Engine
4848
};
@@ -67,7 +67,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass()
6767

6868
var projectEngine = CreateProjectEngine();
6969
var irDocument = CreateIRDocument(projectEngine, codeDocument);
70-
var pass = new ConsolidatedMvcViewDocumentClassifierPass
70+
var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true)
7171
{
7272
Engine = projectEngine.Engine
7373
};
@@ -86,15 +86,15 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass()
8686
[Theory]
8787
[InlineData("/Views/Home/Index.cshtml", "_Views_Home_Index")]
8888
[InlineData("/Areas/MyArea/Views/Home/About.cshtml", "_Areas_MyArea_Views_Home_About")]
89-
public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(string relativePath, string expected)
89+
public void ConsolidatedMvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(string relativePath, string expected)
9090
{
9191
// Arrange
9292
var properties = new RazorSourceDocumentProperties(filePath: "ignored", relativePath: relativePath);
9393
var codeDocument = RazorCodeDocument.Create(RazorSourceDocument.Create("some-content", properties));
9494

9595
var projectEngine = CreateProjectEngine();
9696
var irDocument = CreateIRDocument(projectEngine, codeDocument);
97-
var pass = new ConsolidatedMvcViewDocumentClassifierPass
97+
var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true)
9898
{
9999
Engine = projectEngine.Engine
100100
};
@@ -117,7 +117,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsUpExecuteAsyncMethod()
117117

118118
var projectEngine = CreateProjectEngine();
119119
var irDocument = CreateIRDocument(projectEngine, codeDocument);
120-
var pass = new ConsolidatedMvcViewDocumentClassifierPass
120+
var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true)
121121
{
122122
Engine = projectEngine.Engine
123123
};

0 commit comments

Comments
 (0)