Add wireframe for ConfigureApplicationPart

This commit is contained in:
Pranav K 2018-03-06 17:50:25 -08:00
parent 5af246b554
commit d6ba2ee966
5 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// 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.Reflection;
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
/// <summary>
/// Specifies a contract for synthesizing one or more <see cref="ApplicationPart"/> instances
/// from an <see cref="Assembly"/>.
/// <para>
/// By default, Mvc registers each application assembly that it discovers as an <see cref="AssemblyPart"/>.
/// Assemblies can optionally specify an <see cref="ApplicationPartFactory"/> to configure parts for the assembly
/// by using <see cref="ProvideApplicationPartFactoryAttribute"/>.
/// </para>
/// </summary>
public abstract class ApplicationPartFactory
{
public static readonly string DefaultContextName = "Default";
/// <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);
}
}

View File

@ -0,0 +1,21 @@
// 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;
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
/// <summary>
/// Provides a <see cref="ApplicationPartFactory"/> type.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class ProvideApplicationPartFactoryAttribute : Attribute
{
public ProvideApplicationPartFactoryAttribute(Type factoryType)
{
ApplicationPartFactoryType = factoryType ?? throw new ArgumentNullException(nameof(factoryType));
}
public Type ApplicationPartFactoryType { get; }
}
}

View File

@ -0,0 +1,22 @@
// 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.AspNetCore.Mvc.Core;
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class RelatedAssemblyAttribute : Attribute
{
public RelatedAssemblyAttribute(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(name));
}
}
public string Name { get; }
}
}

View File

@ -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.Reflection;
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
/// <summary>
/// Configures an assembly as a <see cref="CompiledRazorAssemblyPart"/>.
/// </summary>
public class CompiledRazorAssemblyApplicationPartFactory : ApplicationPartFactory
{
/// <inheritdoc />
public override IEnumerable<ApplicationPart> GetApplicationParts(
Assembly assembly,
string configuration)
{
if (assembly == null)
{
throw new ArgumentNullException(nameof(assembly));
}
yield return new CompiledRazorAssemblyPart(assembly);
}
}
}

View File

@ -0,0 +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.Reflection;
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
public class CompiledRazorAssemblyPart : ApplicationPart
{
public CompiledRazorAssemblyPart(Assembly assembly)
{
Assembly = assembly ?? throw new ArgumentNullException(nameof(assembly));
}
public Assembly Assembly { get; }
public override string Name => Assembly.GetName().Name;
}
}