Skip to content

Commit 200c9e2

Browse files
authored
Use attributes for application part discovery (#10271)
* Use attributes for application part discovery Fixes #4332
1 parent e92b480 commit 200c9e2

21 files changed

+222
-997
lines changed

eng/SharedFramework.External.props

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@
5656
<ExternalAspNetCoreAppReference Include="System.Security.Cryptography.Xml" Version="$(SystemSecurityCryptographyXmlPackageVersion)" />
5757
<ExternalAspNetCoreAppReference Include="System.Threading.Channels" Version="$(SystemThreadingChannelsPackageVersion)" />
5858

59-
<!-- Dependencies from dotnet/core-setup -->
60-
<ExternalAspNetCoreAppReference Include="Microsoft.Extensions.DependencyModel" Version="$(MicrosoftExtensionsDependencyModelPackageVersion)" />
61-
6259
<!--
6360
Transitive dependencies of other assemblies in the shared framework. These are listed separately and should not be included directly
6461
when setting `<Reference>`. These are listed for the purpose of tests and servicing builds only.

src/Mvc/Mvc.Core/ref/Microsoft.AspNetCore.Mvc.Core.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<Reference Include="Microsoft.AspNetCore.Routing.Abstractions" />
1616
<Reference Include="Microsoft.AspNetCore.Routing" />
1717
<Reference Include="Microsoft.Extensions.DependencyInjection" />
18-
<Reference Include="Microsoft.Extensions.DependencyModel" />
1918
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions" />
2019
<Reference Include="Microsoft.Extensions.Logging.Abstractions" />
2120
<Reference Include="Microsoft.Extensions.ParameterDefaultValue.Sources" />

src/Mvc/Mvc.Core/ref/Microsoft.AspNetCore.Mvc.Core.netcoreapp3.0.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,12 @@ public abstract partial class ApplicationPart
15471547
protected ApplicationPart() { }
15481548
public abstract string Name { get; }
15491549
}
1550+
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly, AllowMultiple=true)]
1551+
public sealed partial class ApplicationPartAttribute : System.Attribute
1552+
{
1553+
public ApplicationPartAttribute(string assemblyName) { }
1554+
public string AssemblyName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
1555+
}
15501556
public abstract partial class ApplicationPartFactory
15511557
{
15521558
protected ApplicationPartFactory() { }
@@ -1560,13 +1566,12 @@ public ApplicationPartManager() { }
15601566
public System.Collections.Generic.IList<Microsoft.AspNetCore.Mvc.ApplicationParts.IApplicationFeatureProvider> FeatureProviders { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
15611567
public void PopulateFeature<TFeature>(TFeature feature) { }
15621568
}
1563-
public partial class AssemblyPart : Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPart, Microsoft.AspNetCore.Mvc.ApplicationParts.IApplicationPartTypeProvider, Microsoft.AspNetCore.Mvc.ApplicationParts.ICompilationReferencesProvider
1569+
public partial class AssemblyPart : Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPart, Microsoft.AspNetCore.Mvc.ApplicationParts.IApplicationPartTypeProvider
15641570
{
15651571
public AssemblyPart(System.Reflection.Assembly assembly) { }
15661572
public System.Reflection.Assembly Assembly { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
15671573
public override string Name { get { throw null; } }
15681574
public System.Collections.Generic.IEnumerable<System.Reflection.TypeInfo> Types { get { throw null; } }
1569-
public System.Collections.Generic.IEnumerable<string> GetReferencePaths() { throw null; }
15701575
}
15711576
public partial class DefaultApplicationPartFactory : Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartFactory
15721577
{

src/Mvc/Mvc.Core/src/ApplicationParts/ApplicationAssembliesProvider.cs

Lines changed: 0 additions & 295 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
7+
{
8+
/// <summary>
9+
/// Specifies an assembly to be added as an <see cref="ApplicationPart" />.
10+
/// <para>
11+
/// In the ordinary case, MVC will generate <see cref="ApplicationPartAttribute" />
12+
/// instances on the entry assembly for each dependency that references MVC.
13+
/// Each of these assemblies is treated as an <see cref="ApplicationPart" />.
14+
/// </para>
15+
/// </summary>
16+
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
17+
public sealed class ApplicationPartAttribute : Attribute
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of <see cref="ApplicationPartAttribute" />.
21+
/// </summary>
22+
/// <param name="assemblyName">The assembly name.</param>
23+
public ApplicationPartAttribute(string assemblyName)
24+
{
25+
AssemblyName = assemblyName ?? throw new ArgumentNullException(nameof(assemblyName));
26+
}
27+
28+
/// <summary>
29+
/// Gets the assembly name.
30+
/// </summary>
31+
public string AssemblyName { get; }
32+
}
33+
}

0 commit comments

Comments
 (0)