Cleanup ApplicationPartFactory
This commit is contained in:
parent
8590bb9367
commit
56501cb8a0
|
|
@ -19,27 +19,17 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
|||
/// </summary>
|
||||
public abstract class ApplicationPartFactory
|
||||
{
|
||||
public static readonly string DefaultContextName = "Default";
|
||||
|
||||
/// <summary>
|
||||
/// Default implementation for <see cref="ApplicationPartFactory"/>.
|
||||
/// </summary>
|
||||
public static ApplicationPartFactory Default { get; } = new DefaultApplicationPartFactory();
|
||||
|
||||
/// <summary>
|
||||
/// Gets one or more <see cref="ApplicationPart"/> instances for the specified <paramref name="assembly"/>.
|
||||
/// </summary>
|
||||
/// <param name="assembly">The <see cref="Assembly"/>.</param>
|
||||
/// <param name="context">
|
||||
/// The context name. By default, value of this parameter is <see cref="DefaultContextName"/>.
|
||||
/// </param>
|
||||
public abstract IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly, string context);
|
||||
public abstract IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ApplicationPartFactory"/> for the specified assembly.
|
||||
/// <para>
|
||||
/// An assembly may specify an <see cref="ApplicationPartFactory"/> using <see cref="ProvideApplicationPartFactoryAttribute"/>.
|
||||
/// Otherwise, <see cref="ApplicationPartFactory.Default"/> is used.
|
||||
/// Otherwise, <see cref="DefaultApplicationPartFactory"/> is used.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="assembly">The <see cref="Assembly"/>.</param>
|
||||
|
|
@ -54,7 +44,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
|||
var provideAttribute = assembly.GetCustomAttribute<ProvideApplicationPartFactoryAttribute>();
|
||||
if (provideAttribute == null)
|
||||
{
|
||||
return ApplicationPartFactory.Default;
|
||||
return DefaultApplicationPartFactory.Instance;
|
||||
}
|
||||
|
||||
var type = provideAttribute.GetFactoryType();
|
||||
|
|
@ -68,18 +58,5 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
|||
|
||||
return (ApplicationPartFactory)Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
private class DefaultApplicationPartFactory : ApplicationPartFactory
|
||||
{
|
||||
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly, string context)
|
||||
{
|
||||
if (assembly == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
yield return new AssemblyPart(assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
|||
foreach (var assembly in applicationAssemblies)
|
||||
{
|
||||
var partFactory = ApplicationPartFactory.GetApplicationPartFactory(assembly);
|
||||
foreach (var part in partFactory.GetApplicationParts(assembly, context: ApplicationPartFactory.DefaultContextName))
|
||||
foreach (var part in partFactory.GetApplicationParts(assembly))
|
||||
{
|
||||
ApplicationParts.Add(part);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.Reflection;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
||||
{
|
||||
/// <summary>
|
||||
/// Default <see cref="ApplicationPartFactory"/>.
|
||||
/// </summary>
|
||||
public class DefaultApplicationPartFactory : ApplicationPartFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an instance of <see cref="DefaultApplicationPartFactory"/>.
|
||||
/// </summary>
|
||||
public static DefaultApplicationPartFactory Instance { get; } = new DefaultApplicationPartFactory();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sequence of <see cref="ApplicationPart"/> instances that are created by this instance of <see cref="DefaultApplicationPartFactory"/>.
|
||||
/// <para>
|
||||
/// Applications may use this method to get the same behavior as this factory produces during MVC's default part discovery.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="assembly">The <see cref="Assembly"/>.</param>
|
||||
/// <returns>The sequence of <see cref="ApplicationPart"/> instances.</returns>
|
||||
public static IEnumerable<ApplicationPart> GetDefaultApplicationParts(Assembly assembly)
|
||||
{
|
||||
if (assembly == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assembly));
|
||||
}
|
||||
|
||||
yield return new AssemblyPart(assembly);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly)
|
||||
{
|
||||
return GetDefaultApplicationParts(assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
|||
public class NullApplicationPartFactory : ApplicationPartFactory
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly, string context)
|
||||
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly)
|
||||
{
|
||||
return Enumerable.Empty<ApplicationPart>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,15 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
|||
/// </summary>
|
||||
public class CompiledRazorAssemblyApplicationPartFactory : ApplicationPartFactory
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly, string configuration)
|
||||
/// <summary>
|
||||
/// Gets the sequence of <see cref="ApplicationPart"/> instances that are created by this instance of <see cref="DefaultApplicationPartFactory"/>.
|
||||
/// <para>
|
||||
/// Applications may use this method to get the same behavior as this factory produces during MVC's default part discovery.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="assembly">The <see cref="Assembly"/>.</param>
|
||||
/// <returns>The sequence of <see cref="ApplicationPart"/> instances.</returns>
|
||||
public static IEnumerable<ApplicationPart> GetDefaultApplicationParts(Assembly assembly)
|
||||
{
|
||||
if (assembly == null)
|
||||
{
|
||||
|
|
@ -22,5 +29,8 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
|
|||
|
||||
yield return new CompiledRazorAssemblyPart(assembly);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IEnumerable<ApplicationPart> GetApplicationParts(Assembly assembly) => GetDefaultApplicationParts(assembly);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue