-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(abp): updated to abp 8.2.0 and added EnableClassInterceptor
- Loading branch information
1 parent
de381e5
commit 451e916
Showing
6 changed files
with
612 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.