Application parts cleanups

This commit is contained in:
Javier Calvarro Nelson 2018-03-22 20:13:10 -07:00
parent 500279ea98
commit 8f42ce8492
7 changed files with 38 additions and 67 deletions

View File

@ -8,15 +8,6 @@
"Exclusions": {
"DOC_MISSING": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "This library contains precompiled views."
},
"ASSEMBLY_DESCRIPTION": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "Enter justification"
},
"NEUTRAL_RESOURCES_LANGUAGE": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "Enter justification"
},
"SERVICING_ATTRIBUTE": {
"lib/netstandard2.0/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll": "Enter justification"
}
}
}

View File

@ -3,8 +3,8 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59361/",
"sslPort": 0
"applicationUrl": "http://localhost:59364/",
"sslPort": 44315
}
},
"profiles": {

View File

@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
namespace Microsoft.AspNetCore.Authentication
{
@ -190,23 +191,17 @@ namespace Microsoft.AspNetCore.Authentication
private static void AddAdditionalMvcApplicationParts(IServiceCollection services)
{
var thisAssembly = typeof(AzureADB2CAuthenticationBuilderExtensions).Assembly;
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
var additionalParts = GetAdditionalParts();
var mvcBuilder = services
.AddMvc()
.AddRazorPagesOptions(o => o.AllowAreas = true)
.ConfigureApplicationPartManager(apm =>
{
foreach (var reference in relatedAssemblies)
foreach (var part in additionalParts)
{
var factory = (AzureADB2CPartFactory)ApplicationPartFactory.GetApplicationPartFactory(reference);
foreach (var additionalPart in factory.CreateApplicationParts())
if (!apm.ApplicationParts.Any(ap => HasSameName(ap.Name, part.Name)))
{
if (!apm.ApplicationParts.Any(ap => HasSameName(ap.Name, additionalPart.Name)))
{
apm.ApplicationParts.Add(additionalPart);
}
apm.ApplicationParts.Add(part);
}
}
@ -215,5 +210,16 @@ namespace Microsoft.AspNetCore.Authentication
bool HasSameName(string left, string right) => string.Equals(left, right, StringComparison.Ordinal);
}
private static IEnumerable<ApplicationPart> GetAdditionalParts()
{
var thisAssembly = typeof(AzureADB2CAuthenticationBuilderExtensions).Assembly;
var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
foreach (var reference in relatedAssemblies)
{
yield return new CompiledRazorAssemblyPart(reference);
}
}
}
}

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
namespace Microsoft.AspNetCore.Authentication.AzureADB2C.UI
{
/// <summary>
/// <see cref="ApplicationPartFactory"/> for Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll
/// </summary>
public abstract class AzureADB2CPartFactory : ApplicationPartFactory
{
/// <inheritdoc />
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly, string context) =>
Array.Empty<ApplicationPart>();
/// <summary>
/// Creates the list of <see cref="ApplicationPart"/> for a given application.
/// </summary>
/// <returns>The <see cref="ApplicationPart"/> list.</returns>
public abstract IEnumerable<ApplicationPart> CreateApplicationParts();
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
namespace Microsoft.AspNetCore.Authentication.AzureADB2C.UI
{
internal class AzureAdB2CViewsPartFactory : AzureADB2CPartFactory
{
public override IEnumerable<ApplicationPart> CreateApplicationParts()
{
yield return new CompiledRazorAssemblyPart(this.GetType().Assembly);
}
}
}

View File

@ -2,14 +2,14 @@
<PropertyGroup>
<Description>ASP.NET Core Azure Active Directory B2C Integration provides components for easily integrating Azure Active Directory B2C authentication within your ASP.NET Core application.</Description>
<PrecompiledDescription>Precompiled views assembly for the ASP.NET Core Azure Active Directory B2C Integration package.</PrecompiledDescription>
<ViewAssemblyDescription>Precompiled views assembly for the ASP.NET Core Azure Active Directory B2C Integration package.</ViewAssemblyDescription>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageTags>aspnetcore;authentication;AzureADB2C</PackageTags>
<RazorCompileOnBuild>true</RazorCompileOnBuild>
<PrecompiledAssemblyTitle Condition=" '$(PrecompiledAssemblyTitle)' == '' ">$(RazorTargetName).dll</PrecompiledAssemblyTitle>
<PreserveCompilationContext>false</PreserveCompilationContext>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProvideApplicationPartFactoryAttributeTypeName>Microsoft.AspNetCore.Authentication.AzureADB2C.UI.AzureAdB2CViewsPartFactory, Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views</ProvideApplicationPartFactoryAttributeTypeName>
<EnableDefaultCompiledViewAssemblyLoadBehavior>false</EnableDefaultCompiledViewAssemblyLoadBehavior>
</PropertyGroup>
<ItemGroup>
@ -19,9 +19,22 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(MicrosoftAspNetCoreAuthenticationOpenIdConnectPackageVersion)" />
</ItemGroup>
<ItemGroup>
<RazorCompile Include="AzureAdB2CViewsPartFactory.cs" />
<Compile Remove="AzureAdB2CViewsPartFactory.cs" />
</ItemGroup>
<ItemGroup>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyDescriptionAttribute">
<_Parameter1>$(ViewAssemblyDescription)</_Parameter1>
</RazorAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(BuildNumber)' != ''">
<_Parameter1>BuildNumber</_Parameter1>
<_Parameter2>$(BuildNumber)</_Parameter2>
</RazorAssemblyAttribute>
<RazorAssemblyAttribute Include="System.Resources.NeutralResourcesLanguageAttribute" Condition="'$(NeutralLanguage)' != '' and '$(GenerateNeutralResourcesLanguageAttribute)' == 'true'">
<_Parameter1>$(NeutralLanguage)</_Parameter1>
</RazorAssemblyAttribute>
</ItemGroup>
<ItemGroup>
<RazorCompile Include="$(GeneratedCommitHashAttributeFile)" />
<RazorCompile Include="$(GeneratedInternalAspNetCoreAttributeFile)" />
</ItemGroup>
</Project>

View File

@ -3,5 +3,4 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Views.dll, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Authentication.AzureADB2C.UI.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]