Example #1
0
 public IAspectLifecycle GetLifecycle(Type aspectType, IAspectFactory factory)
 {
     return(PerCFlowAspectLifecycle.For(aspectType));
 }
Example #2
0
 public IAspectLifecycle GetLifecycle(Type aspectType, IAspectFactory factory)
 {
     return(new SingletonAspectLifecycle(aspectType, factory));
 }
Example #3
0
 public SingletonAspectLifecycle(Type type, IAspectFactory factory)
 {
     _factory = factory;
     _type    = type;
 }
Example #4
0
 /// <summary>
 /// Create with aspect factory.
 /// </summary>
 /// <param name="factory"></param>
 protected WithAspect(IAspectFactory <TInput, TOutput> factory)
     : this(factory.GeneralAspect, factory.Before, factory.After)
 {
 }
Example #5
0
 public IAspectLifecycle GetLifecycle(Type aspectType, IAspectFactory factory)
 {
     return(new PerThisAspectLifecycle(aspectType, string.IsNullOrEmpty(ActivateOnPointcut)));
 }
Example #6
0
 public void SetFactory <TAspect>(IAspectFactory factory)
 {
     factories[typeof(TAspect)] = factory;
 }
Example #7
0
        /// <inheritdoc />
        public IInvocationWeaveDataProvider Create(Type declaredType, Type targetType)
        {
            var key = new TypePair(declaredType, targetType);

            return(_providerCache.GetOrAdd(key, typeKey =>
            {
                var invocationsData = new ConcurrentDictionary <IInvocationSignature, InvocationWeaveData>(
                    InvocationSignature.InvocationSignatureMethodEqualityComparer.Instance);

                var declaredMethods = typeKey.DeclaringType.GetMethods()
                                      .Union(typeKey.DeclaringType.GetInterfaces()
                                             .SelectMany(i => i.GetMethods()));

                foreach (var declaredMethod in declaredMethods)
                {
                    var targetMethod = ReflectedMethod.GetMethodMap(typeKey.ImplementationType, declaredMethod);
                    if (targetMethod == null)
                    {
                        throw new IvorySharpException(
                            $"Не удалось найти метод '{declaredMethod.Name}' в типе '{typeKey.ImplementationType.Name}'");
                    }

                    var signature = new InvocationSignature(
                        declaredMethod, targetMethod, typeKey.DeclaringType,
                        typeKey.ImplementationType, declaredMethod.GetInvocationType());

                    if (_weavePredicate == null)
                    {
                        _weavePredicate = _weavePredicateHolder.Get();
                    }

                    var isWeaveable = _weavePredicate.IsWeaveable(signature);
                    if (!isWeaveable)
                    {
                        invocationsData.TryAdd(signature, InvocationWeaveData.Unweavable());
                        continue;
                    }

                    if (_factory == null)
                    {
                        _factory = _preInitializerHolder.Get();
                    }

                    var boundaryAspects = _factory.CreateBoundaryAspects(signature);
                    var interceptAspect = _factory.CreateInterceptAspect(signature);

                    if (_pipelineFactory == null)
                    {
                        _pipelineFactory = _pipelineFactoryHolder.Get();
                    }

                    var pipeline = _pipelineFactory.CreatePipeline(signature, boundaryAspects, interceptAspect);
                    var executor = _pipelineFactory.CreateExecutor(signature);

                    invocationsData.TryAdd(signature,
                                           InvocationWeaveData.Weavable(pipeline, executor, boundaryAspects, interceptAspect));
                }

                return new InvocationWeaveDataProvider(invocationsData);
            }));
        }
Example #8
0
 public AspectInterceptor(IAspectFactory aspectFactory)
 {
     if (aspectFactory == null) throw new ArgumentNullException("aspectFactory");
     this.aspectFactory = aspectFactory;
 }
Example #9
0
 public IAspectLifecycle GetLifecycle(Type aspectType, IAspectFactory factory)
 {
     return(new TransientAspectLifecycle(jp => factory.CreateInstance(aspectType, jp)));
 }