/// <inheritdoc /> public void With(PredefinedInterceptors predefinedInterceptor, InterceptionHookOption hookOption = InterceptionHookOption.MethodsAndSetProperties) { switch (predefinedInterceptor) { case PredefinedInterceptors.MethodTraceInterceptor: _container.InterceptWith <MethodTraceInterceptor>(_predicate, hookOption); break; case PredefinedInterceptors.TimeWatchInterceptor: _container.InterceptWith <TimeWatchInterceptor>(_predicate, hookOption); break; default: throw new ArgumentOutOfRangeException(nameof(predefinedInterceptor), predefinedInterceptor, null); } }
private static ProxyGenerationOptions GetProxyGenerationHook(InterceptionHookOption hookOption) { switch (hookOption) { case InterceptionHookOption.MethodsAndSetProperties: return(new ProxyGenerationOptions(new HookMethodsAndSetProperties())); case InterceptionHookOption.MethodsOnly: return(new ProxyGenerationOptions(new HookMethodsButNoProperties())); case InterceptionHookOption.InterceptionAttributOnly: return(new ProxyGenerationOptions(new HookWithInterceptionAttribute())); default: throw new ArgumentOutOfRangeException(nameof(hookOption), hookOption, null); } }
/// <inheritdoc /> public void With <TInterceptor>(InterceptionHookOption hookOption = InterceptionHookOption.MethodsAndSetProperties) where TInterceptor : class, IInterceptor { _container.InterceptWith <TInterceptor>(_predicate, hookOption); }
/// <summary> /// Intercept the given type specifying the predicate an the hook option /// </summary> public static void InterceptWith <TInterceptor>(this Container container, Func <Type, bool> predicate, InterceptionHookOption hookOption) where TInterceptor : class, IInterceptor { var interceptWith = new InterceptionHelper(e => BuildInterceptorExpression <TInterceptor>(container), predicate, GetProxyGenerationHook(hookOption)); container.ExpressionBuilt += interceptWith.OnExpressionBuilt; }