Esempio n. 1
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, _interceptorFactory.CreateInterceptors(interfaceMethod, implementMethod, container));

            if (interfaceMethod != null)
            {
                _pipelines[InterceptorPipelineKey.ForMethod(interfaceMethod)] = pipeline;
            }

            return(pipeline.Count > 0);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 /// <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;
 }
Esempio n. 6
0
        /// <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);
        }
 /// <summary>
 /// Compare two <see cref="InterceptorPipelineKey"/> instances.
 /// </summary>
 /// <param name="other">Object to compare to.</param>
 /// <returns>True if the two keys are equal, false if not.</returns>
 public bool Equals(InterceptorPipelineKey other)
 {
     return(this == other);
 }