示例#1
0
 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);
 }
示例#2
0
    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()));
    }
示例#3
0
    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)));
    }
示例#4
0
 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>();
 }
示例#5
0
    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()));
    }
示例#6
0
    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));
    }
示例#7
0
 public static IInterceptionConfiguration InterceptDbContextSave(this FluentAspectOptions options)
 {
     return(options.InterceptMethod <DbContext>(m =>
                                                m.Name == nameof(DbContext.SaveChanges) ||
                                                m.Name == nameof(DbContext.SaveChangesAsync)));
 }
示例#8
0
 public static IInterceptionConfiguration InterceptMethod <T>(this FluentAspectOptions options,
                                                              Expression <Func <T, object> > method)
 {
     return(options.InterceptMethod <T>(method.GetMethodExpression()));
 }