audit, advisories and doctors/setup work
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StellaOps.Router.Common.Models;
|
||||
|
||||
namespace StellaOps.Microservice;
|
||||
@@ -12,6 +13,7 @@ public sealed class ReflectionEndpointDiscoveryProvider : IEndpointDiscoveryProv
|
||||
private readonly StellaMicroserviceOptions _options;
|
||||
private readonly IEnumerable<Assembly> _assemblies;
|
||||
private readonly IServiceProviderIsService? _serviceProviderIsService;
|
||||
private readonly ILogger? _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReflectionEndpointDiscoveryProvider"/> class.
|
||||
@@ -21,11 +23,13 @@ public sealed class ReflectionEndpointDiscoveryProvider : IEndpointDiscoveryProv
|
||||
public ReflectionEndpointDiscoveryProvider(
|
||||
StellaMicroserviceOptions options,
|
||||
IEnumerable<Assembly>? assemblies = null,
|
||||
IServiceProviderIsService? serviceProviderIsService = null)
|
||||
IServiceProviderIsService? serviceProviderIsService = null,
|
||||
ILogger? logger = null)
|
||||
{
|
||||
_options = options;
|
||||
_assemblies = assemblies ?? AppDomain.CurrentDomain.GetAssemblies();
|
||||
_serviceProviderIsService = serviceProviderIsService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -72,9 +76,41 @@ public sealed class ReflectionEndpointDiscoveryProvider : IEndpointDiscoveryProv
|
||||
endpoints.Add(descriptor);
|
||||
}
|
||||
}
|
||||
catch (ReflectionTypeLoadException)
|
||||
catch (ReflectionTypeLoadException ex)
|
||||
{
|
||||
// Skip assemblies that cannot be loaded
|
||||
if (_logger is not null)
|
||||
{
|
||||
var assemblyName = assembly.FullName ?? assembly.GetName().Name ?? "unknown";
|
||||
if (ex.LoaderExceptions is not null && ex.LoaderExceptions.Length > 0)
|
||||
{
|
||||
foreach (var loaderException in ex.LoaderExceptions)
|
||||
{
|
||||
if (loaderException is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_logger.LogWarning(
|
||||
loaderException,
|
||||
"Endpoint discovery skipped assembly {Assembly} due to type load error.",
|
||||
assemblyName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning(
|
||||
ex,
|
||||
"Endpoint discovery skipped assembly {Assembly} due to type load error.",
|
||||
assemblyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogWarning(
|
||||
ex,
|
||||
"Endpoint discovery skipped assembly {Assembly} due to reflection error.",
|
||||
assembly.FullName ?? assembly.GetName().Name ?? "unknown");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user