Add exclusion filter setting to typefinder settings (#14426)

* Obsolete constructor with deprecated IScopeProvider

* Add exclusion setting to typefinder settings

* The old TypeFinder constructor calls the new constructor now instead and excluded duplicates by using Union instead of Concat.

* Revert "The old TypeFinder constructor calls the new constructor now instead and excluded duplicates by using Union instead of Concat."

This reverts commit 87801c6c1cbaa6adab6f29dba1e876a586e05885.

* Add changes to TypeFinder

* Do not use null when type is not nullable

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Anders Reus
2023-08-15 09:46:27 +02:00
committed by Bjarke Berg
parent b743e715d4
commit 30f0cfc15d
3 changed files with 16 additions and 1 deletions

View File

@@ -21,7 +21,7 @@ public class TypeFinder : ITypeFinder
/// its an exact name match /// its an exact name match
/// NOTE this means that "foo." will NOT exclude "foo.dll" but only "foo.*.dll" /// NOTE this means that "foo." will NOT exclude "foo.dll" but only "foo.*.dll"
/// </remarks> /// </remarks>
internal static readonly string[] KnownAssemblyExclusionFilter = internal static string[] KnownAssemblyExclusionFilter =
{ {
"mscorlib,", "netstandard,", "System,", "Antlr3.", "AutoMapper,", "AutoMapper.", "Autofac,", // DI "mscorlib,", "netstandard,", "System,", "Antlr3.", "AutoMapper,", "AutoMapper.", "Autofac,", // DI
"Autofac.", "AzureDirectory,", "Castle.", // DI, tests "Autofac.", "AzureDirectory,", "Castle.", // DI, tests
@@ -49,11 +49,20 @@ public class TypeFinder : ITypeFinder
private string[]? _assembliesAcceptingLoadExceptions; private string[]? _assembliesAcceptingLoadExceptions;
private volatile HashSet<Assembly>? _localFilteredAssemblyCache; private volatile HashSet<Assembly>? _localFilteredAssemblyCache;
[Obsolete("Please use the constructor taking all parameters. This constructor will be removed in V14.")]
public TypeFinder(ILogger<TypeFinder> logger, IAssemblyProvider assemblyProvider, ITypeFinderConfig? typeFinderConfig = null) public TypeFinder(ILogger<TypeFinder> logger, IAssemblyProvider assemblyProvider, ITypeFinderConfig? typeFinderConfig = null)
: this(logger, assemblyProvider, null, typeFinderConfig)
{ }
public TypeFinder(ILogger<TypeFinder> logger, IAssemblyProvider assemblyProvider, string[]? additionalExlusionAssemblies, ITypeFinderConfig? typeFinderConfig = null)
{ {
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); _logger = logger ?? throw new ArgumentNullException(nameof(logger));
_assemblyProvider = assemblyProvider; _assemblyProvider = assemblyProvider;
_typeFinderConfig = typeFinderConfig; _typeFinderConfig = typeFinderConfig;
if (additionalExlusionAssemblies is not null)
{
KnownAssemblyExclusionFilter = KnownAssemblyExclusionFilter.Union(additionalExlusionAssemblies).ToArray();
}
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -22,4 +22,9 @@ public class TypeFinderSettings
/// scanning for plugins based on different root referenced assemblies you can add the assembly name to this list. /// scanning for plugins based on different root referenced assemblies you can add the assembly name to this list.
/// </summary> /// </summary>
public IEnumerable<string>? AdditionalEntryAssemblies { get; set; } public IEnumerable<string>? AdditionalEntryAssemblies { get; set; }
/// <summary>
/// Gets or sets a value for the assemblies that will be excluded from scanning.
/// </summary>
public string[] AdditionalAssemblyExclusionEntries { get; set; } = Array.Empty<string>();
} }

View File

@@ -200,6 +200,7 @@ public static class ServiceCollectionExtensions
var typeFinder = new TypeFinder( var typeFinder = new TypeFinder(
loggerFactory.CreateLogger<TypeFinder>(), loggerFactory.CreateLogger<TypeFinder>(),
assemblyProvider, assemblyProvider,
typeFinderSettings.AdditionalAssemblyExclusionEntries,
typeFinderConfig); typeFinderConfig);
var typeLoader = new TypeLoader(typeFinder, loggerFactory.CreateLogger<TypeLoader>()); var typeLoader = new TypeLoader(typeFinder, loggerFactory.CreateLogger<TypeLoader>());