Support linking with IHubFilter (#24780)

- Mark AddFilter to make sure constructors don't get erased during aggressive linking
This commit is contained in:
David Fowler 2020-08-11 10:39:52 -07:00 committed by GitHub
parent 8e5533f2a3
commit fcf2823f3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.SignalR.Internal;
namespace Microsoft.AspNetCore.SignalR
@ -37,7 +38,7 @@ namespace Microsoft.AspNetCore.SignalR
/// </summary>
/// <typeparam name="TFilter">The <see cref="IHubFilter"/> type that will be added to the options.</typeparam>
/// <param name="options">The options to add a filter to.</param>
public static void AddFilter<TFilter>(this HubOptions options) where TFilter : IHubFilter
public static void AddFilter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]TFilter>(this HubOptions options) where TFilter : IHubFilter
{
_ = options ?? throw new ArgumentNullException(nameof(options));
@ -49,7 +50,7 @@ namespace Microsoft.AspNetCore.SignalR
/// </summary>
/// <param name="options">The options to add a filter to.</param>
/// <param name="filterType">The <see cref="IHubFilter"/> type that will be added to the options.</param>
public static void AddFilter(this HubOptions options, Type filterType)
public static void AddFilter(this HubOptions options, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type filterType)
{
_ = options ?? throw new ArgumentNullException(nameof(options));
_ = filterType ?? throw new ArgumentNullException(nameof(filterType));

View File

@ -4,6 +4,7 @@
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
@ -12,9 +13,11 @@ namespace Microsoft.AspNetCore.SignalR.Internal
internal class HubFilterFactory : IHubFilter
{
private readonly ObjectFactory _objectFactory;
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
private readonly Type _filterType;
public HubFilterFactory(Type filterType)
public HubFilterFactory([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type filterType)
{
_objectFactory = ActivatorUtilities.CreateFactory(filterType, Array.Empty<Type>());
_filterType = filterType;