public static FluentAspectOptions InterceptDbContextSaveWithAudit(this FluentAspectOptions options) { options.InterceptMethod <DbContext>(m => m.Name == nameof(DbContext.SaveChanges) || m.Name == nameof(DbContext.SaveChangesAsync)) .With <AuditDbContextInterceptor>(); return(options); }
public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options, Expression <Func <MethodInfo, bool> > andExpression) { Expression <Func <MethodInfo, bool> > expression = m => m.DeclaringType !.IsAssignableTo <T>(); expression = expression.And(Guard.NotNull(andExpression, nameof(andExpression))); return(options.InterceptMethod(expression.Compile())); }
public static IInterceptionConfiguration InterceptMethod(this FluentAspectOptions options, MethodInfo method) { if (null == method) { throw new ArgumentNullException(nameof(method)); } var methodSignature = method.GetSignature(); return(options.InterceptMethod(m => m.GetSignature().Equals(methodSignature))); }
static FluentAspects() { AspectOptions = new FluentAspectOptions(); // register built-in ignore interceptors AspectOptions .NoInterceptType(t => t.Namespace?.StartsWith("WeihanLi.Common.Aspect") == true) ; // register built-in necessary interceptors AspectOptions.InterceptAll() .With <TryInvokeInterceptor>(); AspectOptions.InterceptMethod <IDisposable>(m => m.Dispose()) .With <DisposableInterceptor>(); }
public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options, MethodCallExpression methodCallExpression) { var innerMethod = methodCallExpression.Method; if (null == innerMethod) { throw new InvalidOperationException("no method found"); } Expression <Func <MethodInfo, bool> > expression = m => m.DeclaringType !.IsAssignableTo <T>(); var methodSignature = innerMethod.GetSignature(); expression = expression.And(m => m.GetSignature().Equals(methodSignature)); return(options.InterceptMethod(expression.Compile())); }
public static IInterceptionConfiguration InterceptPropertySetter <T>(this FluentAspectOptions options, Expression <Func <T, object> > expression) { var prop = expression.GetProperty(); if (null == prop) { throw new InvalidOperationException("no property found"); } if (!prop.CanWrite || prop.SetMethod == null) { throw new InvalidOperationException($"the property {prop.Name} can not write"); } return(options.InterceptMethod <T>(prop.SetMethod)); }
public static IInterceptionConfiguration InterceptDbContextSave(this FluentAspectOptions options) { return(options.InterceptMethod <DbContext>(m => m.Name == nameof(DbContext.SaveChanges) || m.Name == nameof(DbContext.SaveChangesAsync))); }
public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options, Expression <Func <T, object> > method) { return(options.InterceptMethod <T>(method.GetMethodExpression())); }