Skip to content

Commit

Permalink
feat(abp): updated to abp 8.2.0 and added EnableClassInterceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
zhifenglee-aelf committed Oct 21, 2024
1 parent de381e5 commit 451e916
Show file tree
Hide file tree
Showing 6 changed files with 612 additions and 22 deletions.
19 changes: 17 additions & 2 deletions AElf.ExceptionHandler.ABP/AElf.ExceptionHandler.ABP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
<RootNamespace>AElf.ExceptionHandler.ABP</RootNamespace>
</PropertyGroup>

<PropertyGroup>
<DefineConstants>$(DefineConstants);ABP_VERSION_8_2_0</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Volo.Abp.Core" Version="8.0.5" />
<PackageReference Include="AElf.ExceptionHandler" Version="1.7.0" />
<PackageReference Include="Volo.Abp.Core" Version="8.2.0" />
<PackageReference Include="Volo.Abp.Castle.Core" Version="8.2.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="8.2.0" />
<PackageReference Include="AElf.ExceptionHandler" Version="1.8.0" />
</ItemGroup>

<PropertyGroup>
Expand All @@ -31,4 +37,13 @@
<None Include="../LICENSE" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Mvc.Abstractions">
<HintPath>..\..\..\..\..\..\usr\local\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.6\Microsoft.AspNetCore.Mvc.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNetCore.Mvc.Core">
<HintPath>..\..\..\..\..\..\usr\local\share\dotnet\shared\Microsoft.AspNetCore.App\8.0.6\Microsoft.AspNetCore.Mvc.Core.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
46 changes: 31 additions & 15 deletions AElf.ExceptionHandler.ABP/AOPExceptionModule.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
using System.Reflection;
using AElf.ExceptionHandler.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Castle;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Modularity;

namespace AElf.ExceptionHandler.ABP;

[DependsOn(
typeof(AbpCastleCoreModule)
)]
public class AOPExceptionModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddExceptionHandler();
context.Services.AddTransient<ExceptionHandlerInterceptor>();

context.Services.OnRegistered(options =>
}

public override void PostConfigureServices(ServiceConfigurationContext context)
{
base.PostConfigureServices(context);

var builder = context.Services.GetContainerBuilder();

context.Services.OnRegistered(RegisterExceptionHandlerIfNeeded);

AutofacRegistration.Register(builder, context.Services, null);
}

private static void RegisterExceptionHandlerIfNeeded(IOnServiceRegistredContext context)
{
if(ShouldIntercept(context.ImplementationType))
{
var methodInfos = options.ImplementationType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
// Check if any of the class methods is decorated with the ExceptionHandlerAttribute
foreach (var methodInfo in methodInfos)
{
if (methodInfo.IsDefined(typeof(ExceptionHandlerAttribute), true))
{
var result = options.Interceptors.TryAdd<ExceptionHandlerInterceptor>();
break;
}
}
});
context.Interceptors.TryAdd<ExceptionHandlerInterceptor>();
}
}

private static bool ShouldIntercept(Type type)
{
return ExceptionHandlerHelper.IsExceptionHandlerType(type.GetTypeInfo());
//return !DynamicProxyIgnoreTypes.Contains(type) && ExceptionHandlerHelper.IsExceptionHandlerType(type.GetTypeInfo());
}
}
Loading

0 comments on commit 451e916

Please sign in to comment.