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:
@@ -21,7 +21,7 @@ public class TypeFinder : ITypeFinder
|
||||
/// its an exact name match
|
||||
/// NOTE this means that "foo." will NOT exclude "foo.dll" but only "foo.*.dll"
|
||||
/// </remarks>
|
||||
internal static readonly string[] KnownAssemblyExclusionFilter =
|
||||
internal static string[] KnownAssemblyExclusionFilter =
|
||||
{
|
||||
"mscorlib,", "netstandard,", "System,", "Antlr3.", "AutoMapper,", "AutoMapper.", "Autofac,", // DI
|
||||
"Autofac.", "AzureDirectory,", "Castle.", // DI, tests
|
||||
@@ -49,11 +49,20 @@ public class TypeFinder : ITypeFinder
|
||||
private string[]? _assembliesAcceptingLoadExceptions;
|
||||
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)
|
||||
: this(logger, assemblyProvider, null, typeFinderConfig)
|
||||
{ }
|
||||
|
||||
public TypeFinder(ILogger<TypeFinder> logger, IAssemblyProvider assemblyProvider, string[]? additionalExlusionAssemblies, ITypeFinderConfig? typeFinderConfig = null)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_assemblyProvider = assemblyProvider;
|
||||
_typeFinderConfig = typeFinderConfig;
|
||||
if (additionalExlusionAssemblies is not null)
|
||||
{
|
||||
KnownAssemblyExclusionFilter = KnownAssemblyExclusionFilter.Union(additionalExlusionAssemblies).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -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.
|
||||
/// </summary>
|
||||
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>();
|
||||
}
|
||||
|
||||
@@ -200,6 +200,7 @@ public static class ServiceCollectionExtensions
|
||||
var typeFinder = new TypeFinder(
|
||||
loggerFactory.CreateLogger<TypeFinder>(),
|
||||
assemblyProvider,
|
||||
typeFinderSettings.AdditionalAssemblyExclusionEntries,
|
||||
typeFinderConfig);
|
||||
|
||||
var typeLoader = new TypeLoader(typeFinder, loggerFactory.CreateLogger<TypeLoader>());
|
||||
|
||||
Reference in New Issue
Block a user