Skip to content

Commit

Permalink
feat(services): removed exception handler services to be added later
Browse files Browse the repository at this point in the history
  • Loading branch information
zhifenglee-aelf committed Nov 13, 2024
1 parent 4422d28 commit a390b4d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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<ServiceDescriptor> ExceptionHandlerServices { get; set; } = new List<ServiceDescriptor>();
public static IHostBuilder UseAElfExceptionHandler(this IHostBuilder hostBuilder)
{
return hostBuilder.ConfigureServices((_, services) =>
{
hostBuilder.ConfigureContainer<ContainerBuilder>((_, builder) =>
{
// Register the exception handler services
foreach (var serviceDescriptor in ExceptionHandlerServices)
{
services.Add(serviceDescriptor);
}

AutofacRegistration.Register(builder, services, null);
});
});
Expand Down
2 changes: 2 additions & 0 deletions AElf.ExceptionHandler.ABP/AOPExceptionModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions AElf.ExceptionHandler.ABP/AutofacRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a390b4d

Please sign in to comment.