Skip to content

Commit 02f5374

Browse files
authored
[Static web assets] Removes private reflection from Identity.DefaultUI.WebSite by giving it IVT access in Hosting
These tests need to disable polling within the underlying file provider, given that the provider is internal, they were using reflection to access them and modify the polling setting. This change gives the test assembly internals visible to access so that it can do so without resorting to use private reflection.
1 parent 0ca2ed9 commit 02f5374

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

AspNetCore.sln

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31320.298
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31613.370
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "eng", "eng", "{C28A32F6-8314-412E-9F3B-CBD31C23E878}"
77
EndProject
@@ -1638,6 +1638,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Razor.
16381638
EndProject
16391639
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientApp", "src\Servers\Kestrel\samples\HttpClientApp\HttpClientApp.csproj", "{514726D2-3D2E-44C1-B056-163E37DE3E8B}"
16401640
EndProject
1641+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets", "{48526D13-69E2-4409-A57B-C3FA3C64B4F7}"
1642+
EndProject
1643+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Identity.DefaultUI.WebSite", "src\Identity\testassets\Identity.DefaultUI.WebSite\Identity.DefaultUI.WebSite.csproj", "{835A4E0F-A697-4B69-9736-3E99D163C4B9}"
1644+
EndProject
16411645
Global
16421646
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16431647
Debug|Any CPU = Debug|Any CPU
@@ -7817,6 +7821,18 @@ Global
78177821
{514726D2-3D2E-44C1-B056-163E37DE3E8B}.Release|x64.Build.0 = Release|Any CPU
78187822
{514726D2-3D2E-44C1-B056-163E37DE3E8B}.Release|x86.ActiveCfg = Release|Any CPU
78197823
{514726D2-3D2E-44C1-B056-163E37DE3E8B}.Release|x86.Build.0 = Release|Any CPU
7824+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7825+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
7826+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x64.ActiveCfg = Debug|Any CPU
7827+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x64.Build.0 = Debug|Any CPU
7828+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x86.ActiveCfg = Debug|Any CPU
7829+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Debug|x86.Build.0 = Debug|Any CPU
7830+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
7831+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|Any CPU.Build.0 = Release|Any CPU
7832+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x64.ActiveCfg = Release|Any CPU
7833+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x64.Build.0 = Release|Any CPU
7834+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x86.ActiveCfg = Release|Any CPU
7835+
{835A4E0F-A697-4B69-9736-3E99D163C4B9}.Release|x86.Build.0 = Release|Any CPU
78207836
EndGlobalSection
78217837
GlobalSection(SolutionProperties) = preSolution
78227838
HideSolutionNode = FALSE
@@ -8628,7 +8644,8 @@ Global
86288644
{17459B97-1AA3-4154-83D3-C6BDC9FA3F85} = {022B4B80-E813-4256-8034-11A68146F4EF}
86298645
{247E7B6F-FBA2-41A9-BA03-C7C4DF28091C} = {B27FBAC2-ADA3-4A05-B232-64011B6B2DA3}
86308646
{514726D2-3D2E-44C1-B056-163E37DE3E8B} = {7B976D8F-EA31-4C0B-97BD-DFD9B3CC86FB}
8631-
{B2ACFA01-3046-4A32-B90A-F9537F51BF85} = {6126DCE4-9692-4EE2-B240-C65743572995}
8647+
{48526D13-69E2-4409-A57B-C3FA3C64B4F7} = {9F21A235-436E-4020-A076-1DF4F89D0CA0}
8648+
{835A4E0F-A697-4B69-9736-3E99D163C4B9} = {48526D13-69E2-4409-A57B-C3FA3C64B4F7}
86328649
EndGlobalSection
86338650
GlobalSection(ExtensibilityGlobals) = postSolution
86348651
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

src/Hosting/Hosting/src/Microsoft.AspNetCore.Hosting.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@
3434
<Compile Include="$(SharedSourceRoot)TypeNameHelper\*.cs" />
3535
</ItemGroup>
3636

37+
<ItemGroup>
38+
<InternalsVisibleTo Include="Identity.DefaultUI.WebSite" />
39+
</ItemGroup>
40+
3741
</Project>

src/Identity/testassets/Identity.DefaultUI.WebSite/StartupBase.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Extensions.DependencyInjection;
1616
using Microsoft.Extensions.FileProviders;
1717
using Microsoft.Extensions.Hosting;
18+
using Microsoft.AspNetCore.StaticWebAssets;
1819

1920
namespace Identity.DefaultUI.WebSite
2021
{
@@ -102,11 +103,8 @@ public static void DisableFilePolling(IWebHostEnvironment env)
102103
case PhysicalFileProvider physical:
103104
physical.UseActivePolling = false;
104105
break;
105-
case IFileProvider staticWebAssets when staticWebAssets.GetType().Name == "StaticWebAssetsFileProvider":
106-
GetUnderlyingProvider(staticWebAssets).UseActivePolling = false;
107-
break;
108-
case IFileProvider manifestStaticWebAssets when manifestStaticWebAssets.GetType().Name == "ManifestStaticWebAssetFileProvider":
109-
foreach (var provider in GetUnderlyingProviders(manifestStaticWebAssets))
106+
case ManifestStaticWebAssetFileProvider manifestStaticWebAssets:
107+
foreach (var provider in manifestStaticWebAssets.FileProviders)
110108
{
111109
pendingProviders.Push(provider);
112110
}
@@ -124,18 +122,5 @@ public static void DisableFilePolling(IWebHostEnvironment env)
124122
}
125123
}
126124
}
127-
128-
private static IFileProvider[] GetUnderlyingProviders(IFileProvider manifestStaticWebAssets)
129-
{
130-
return (IFileProvider[])manifestStaticWebAssets
131-
.GetType()
132-
.GetField("_fileProviders", BindingFlags.NonPublic | BindingFlags.Instance)
133-
.GetValue(manifestStaticWebAssets);
134-
}
135-
136-
private static PhysicalFileProvider GetUnderlyingProvider(IFileProvider staticWebAssets)
137-
{
138-
return (PhysicalFileProvider) staticWebAssets.GetType().GetProperty("InnerProvider").GetValue(staticWebAssets);
139-
}
140125
}
141126
}

src/Shared/StaticWebAssets/StaticWebAssetsFileProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public ManifestStaticWebAssetFileProvider(StaticWebAssetManifest manifest, Func<
3535
_root = manifest.Root;
3636
}
3737

38+
// For testing purposes only
39+
internal IFileProvider[] FileProviders => _fileProviders;
40+
3841
public IDirectoryContents GetDirectoryContents(string subpath)
3942
{
4043
if (subpath == null)

0 commit comments

Comments
 (0)