/// <summary> /// Initialize the pipeline for the given method, creating it if necessary. /// </summary> /// <param name="interfaceMethod"><see cref="MethodInfo"/> for the interface method (may be null if no interface).</param> /// <param name="implementMethod"><see cref="MethodInfo"/> for implementing method.</param> /// <param name="container">Service container that can be used to resolve interceptors.</param> /// <returns>True if the pipeline has any interceptor in it, false if not.</returns> public bool InitializePipeline(MethodInfo interfaceMethod, MethodInfo implementMethod, IServiceContainer container) { if (implementMethod == null) { throw new ArgumentNullException(nameof(implementMethod)); } var pipeline = CreatePipeline(implementMethod, _interceptorFactory.CreateInterceptors(interfaceMethod, implementMethod, container)); if (interfaceMethod != null) { _pipelines[InterceptorPipelineKey.ForMethod(interfaceMethod)] = pipeline; } return(pipeline.Count > 0); }
/// <summary> /// Initialize the pipeline for the given method, creating it if necessary. /// </summary> /// <param name="interfaceMethod"><see cref="MethodInfo"/> for the interface method (may be null if no interface).</param> /// <param name="implementMethod"><see cref="MethodInfo"/> for implementing method.</param> /// <param name="container">Service container that can be used to resolve interceptors.</param> /// <returns>True if the pipeline has any interceptor in it, false if not.</returns> public bool InitializePipeline(MethodInfo interfaceMethod, MethodInfo implementMethod, IServiceContainer container) { if (implementMethod == null) { throw new ArgumentNullException(nameof(implementMethod)); } var pipeline = CreatePipeline(implementMethod, from attribute in GetInterceptorAttributes(interfaceMethod, implementMethod) orderby attribute.Order select attribute.CreateInterceptor(container)); if (interfaceMethod != null) { _pipelines[InterceptorPipelineKey.ForMethod(interfaceMethod)] = pipeline; } return(pipeline.Count > 0); }
private InterceptorPipeline CreatePipeline(MethodInfo method, IEnumerable <IInterceptor> interceptors) { InterceptorPipelineKey key = InterceptorPipelineKey.ForMethod(method); if (_pipelines.ContainsKey(key)) { return(_pipelines[key]); } #if NetCore var baseMethod = method.GetRuntimeBaseDefinition(); #else var baseMethod = method.GetBaseDefinition(); #endif if (Equals(baseMethod, method)) { _pipelines[key] = new InterceptorPipeline(interceptors); return(_pipelines[key]); } var basePipeline = CreatePipeline(baseMethod, interceptors); _pipelines[key] = basePipeline; return(basePipeline); }
private InterceptorPipeline CreatePipeline(MethodBase methodBase, IEnumerable <IInterceptor> interceptors) { InterceptorPipelineKey key = InterceptorPipelineKey.ForMethod(methodBase); if (_pipelines.ContainsKey(key)) { return(_pipelines[key]); } InterceptorPipeline pipeline; #if NetCore if (methodBase.IsConstructor) #else if (methodBase.MemberType == MemberTypes.Constructor) #endif { pipeline = new InterceptorPipeline(interceptors); _pipelines[key] = pipeline; return(pipeline); } var method = (MethodInfo)methodBase; #if NetCore var baseMethod = method.GetRuntimeBaseDefinition(); #else var baseMethod = method.GetBaseDefinition(); #endif if (baseMethod == null || Equals(baseMethod, method)) { pipeline = new InterceptorPipeline(interceptors); _pipelines[key] = pipeline; return(pipeline); } pipeline = CreatePipeline(baseMethod, interceptors); _pipelines[key] = pipeline; return(pipeline); }
/// <summary> /// Set a new pipeline for a methodBase. /// </summary> /// <param name="method">The methodBase on which the pipeline should be set.</param> /// <param name="pipeline">The new pipeline.</param> public void SetPipeline(MethodBase method, InterceptorPipeline pipeline) { _pipelines[InterceptorPipelineKey.ForMethod(method)] = pipeline; }
/// <summary> /// Retrieve the pipeline associated with the requested <paramref name="method"/>. /// </summary> /// <param name="method">The methodBase for which the pipeline is being requested.</param> /// <returns>The handler pipeline for the given methodBase. If no pipeline has /// been set, returns a new empty pipeline.</returns> public InterceptorPipeline GetPipeline(MethodBase method) { InterceptorPipeline pipeline; return(_pipelines.TryGetValue(InterceptorPipelineKey.ForMethod(method), out pipeline) ? pipeline : InterceptorPipeline.Empty); }