/// <summary> /// Retrieve the pipeline associated with the requested <paramref name="method"/>. /// </summary> /// <param name="method">The method for which the pipeline is being requested.</param> /// <returns>The handler pipeline for the given method. If no pipeline has /// been set, returns a new empty pipeline.</returns> public HandlerPipeline GetPipeline(MethodBase method) { HandlerPipelineKey key = HandlerPipelineKey.ForMethod(method); HandlerPipeline pipeline = EmptyPipeline; if (pipelines.ContainsKey(key)) { pipeline = pipelines[key]; } return(pipeline); }
private HandlerPipeline CreatePipeline(MethodInfo method, IEnumerable <ICallHandler> handlers) { HandlerPipelineKey key = HandlerPipelineKey.ForMethod(method); if (pipelines.ContainsKey(key)) { return(pipelines[key]); } if (method.GetBaseDefinition() == method) { pipelines[key] = new HandlerPipeline(handlers); return(pipelines[key]); } var basePipeline = CreatePipeline(method.GetBaseDefinition(), handlers); pipelines[key] = basePipeline; return(basePipeline); }
/// <summary> /// Applies the policy injection handlers configured for the invoked method. /// </summary> /// <param name="input">Inputs to the current call to the target.</param> /// <param name="getNext">Delegate to execute to get the next delegate in the handler /// chain.</param> /// <returns>Return value from the target.</returns> public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) { Guard.ArgumentNotNull(input, "input"); Guard.ArgumentNotNull(getNext, "getNext"); HandlerPipeline pipeline = GetPipeline(input.MethodBase); return(pipeline.Invoke( input, delegate(IMethodInvocation policyInjectionInput, GetNextHandlerDelegate policyInjectionInputGetNext) { try { return getNext()(policyInjectionInput, getNext); } catch (TargetInvocationException ex) { // The outer exception will always be a reflection exception; we want the inner, which is // the underlying exception. return policyInjectionInput.CreateExceptionMethodReturn(ex.InnerException); } })); }
/// <summary> /// Set a new pipeline for a method. /// </summary> /// <param name="method">The method on which the pipeline should be set.</param> /// <param name="pipeline">The new pipeline.</param> public void SetPipeline(MethodBase method, HandlerPipeline pipeline) { HandlerPipelineKey key = HandlerPipelineKey.ForMethod(method); pipelines[key] = pipeline; }