/// <summary> /// Applies an ordering strategy to the interceptors /// </summary> /// <typeparam name="TStrategy">Strategy (Class) Type</typeparam> /// <returns><see cref="SimpleProxyConfiguration"/> so that configuration can be chained</returns> public SimpleProxyConfiguration WithOrderingStrategy <TStrategy>() where TStrategy : IOrderingStrategy { // Creates a new instance of the Ordering Strategy and assigns it the configuration this.OrderingStrategy = Activator.CreateInstance <TStrategy>(); // Return the ProxyConfiguration for chaining configuration return(this); }
private static void InterceptAfterProceed(List <InvocationContext> invocationMetadataCollection, IOrderingStrategy orderingStrategy) { // Process the AFTER Interceptions foreach (var invocationContext in orderingStrategy.OrderAfterInterception(invocationMetadataCollection)) { invocationContext.Interceptor.AfterInvoke(invocationContext, invocationContext.GetMethodReturnValue()); } }
private bool InterceptBeforeProceed(IInvocation invocation, out List <InvocationContext> invocationMetadataCollection, out IOrderingStrategy orderingStrategy) { // Map the configured interceptors to this type based on its attributes invocationMetadataCollection = InvocationExtensions.GetInterceptorMetadataForMethod(invocation, this.serviceProvider, this.proxyConfiguration); // If there are no configured interceptors, leave now if (invocationMetadataCollection == null || !invocationMetadataCollection.Any()) { orderingStrategy = null; return(false); } // Get the Ordering Strategy for Interceptors orderingStrategy = this.proxyConfiguration.OrderingStrategy; // Process the BEFORE Interceptions foreach (var invocationContext in orderingStrategy.OrderBeforeInterception(invocationMetadataCollection)) { invocationContext.Interceptor.BeforeInvoke(invocationContext); } return(true); }