From a390b4d7e9e36a5b0cd615d0d272ffbd6311d08d Mon Sep 17 00:00:00 2001 From: zhifenglee-aelf Date: Wed, 13 Nov 2024 22:31:53 +0800 Subject: [PATCH] feat(services): removed exception handler services to be added later --- .../AElfExceptionHandlerHostBuilderExtensions.cs | 8 ++++++++ AElf.ExceptionHandler.ABP/AOPExceptionModule.cs | 2 ++ AElf.ExceptionHandler.ABP/AutofacRegistration.cs | 6 ------ 3 files changed, 10 insertions(+), 6 deletions(-) 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)