diff --git a/AElf.ExceptionHandler.ABP/AElfExceptionHandlerHostBuilderExtensions.cs b/AElf.ExceptionHandler.ABP/AElfExceptionHandlerHostBuilderExtensions.cs index a94fc26..cf33296 100644 --- a/AElf.ExceptionHandler.ABP/AElfExceptionHandlerHostBuilderExtensions.cs +++ b/AElf.ExceptionHandler.ABP/AElfExceptionHandlerHostBuilderExtensions.cs @@ -1,16 +1,24 @@ using Autofac; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace AElf.ExceptionHandler.ABP; public static class AElfExceptionHandlerHostBuilderExtensions { + public static IList ExceptionHandlerServices { get; set; } = new List(); public static IHostBuilder UseAElfExceptionHandler(this IHostBuilder hostBuilder) { return hostBuilder.ConfigureServices((_, services) => { hostBuilder.ConfigureContainer((_, builder) => { + // Register the exception handler services + foreach (var serviceDescriptor in ExceptionHandlerServices) + { + services.Add(serviceDescriptor); + } + AutofacRegistration.Register(builder, services, null); }); }); diff --git a/AElf.ExceptionHandler.ABP/AOPExceptionModule.cs b/AElf.ExceptionHandler.ABP/AOPExceptionModule.cs index d264834..73b43eb 100644 --- a/AElf.ExceptionHandler.ABP/AOPExceptionModule.cs +++ b/AElf.ExceptionHandler.ABP/AOPExceptionModule.cs @@ -21,6 +21,8 @@ public override void PostConfigureServices(ServiceConfigurationContext context) { base.PostConfigureServices(context); context.Services.OnRegistered(RegisterExceptionHandlerIfNeeded); + //remove all services that are satisfies ShouldIntercept. To be registered again later. + AElfExceptionHandlerHostBuilderExtensions.ExceptionHandlerServices = context.Services.RemoveAll(s => s.ImplementationType != null && ShouldIntercept(s.ImplementationType)); } private static void RegisterExceptionHandlerIfNeeded(IOnServiceRegistredContext context) diff --git a/AElf.ExceptionHandler.ABP/AutofacRegistration.cs b/AElf.ExceptionHandler.ABP/AutofacRegistration.cs index f72794a..be98e1c 100644 --- a/AElf.ExceptionHandler.ABP/AutofacRegistration.cs +++ b/AElf.ExceptionHandler.ABP/AutofacRegistration.cs @@ -317,12 +317,6 @@ public static void Register( { continue; } - - // Class type are already registered properly and can be ignored - if (descriptor.ServiceType.IsClass) - { - continue; - } } if (implementationType != null)