Example #1
0
        public object Intercept(IJointPoint jp)
        {
            var interception = new InterceptionImpl();

            try
            {
                Before(interception);

                if (!interception.IsPrevented)
                {
                    interception.ReturnValue = jp.Execute();
                }

                Success(jp, interception.Reset(), interception.ReturnValue);
            }
            catch (Exception e)
            {
                Error(jp, interception.Reset(), e);
                if (!interception.IsPrevented)
                {
                    throw;
                }
            }
            finally
            {
                Exit(jp, interception.Reset(), interception.ReturnValue);
            }

            return(interception.ReturnValue);
        }
Example #2
0
        public object GetAspect(IJointPoint jointPoint)
        {
            if (jointPoint.This == null)
            {
                return(null);
            }

            return(_aspectByTypes.GetOrPut(jointPoint.This.GetType(), () => _factory(jointPoint)));
        }
Example #3
0
        public object CreateInstance(Type type, IJointPoint joinpoint)
        {
            var obj = Instantiate(type);

            if (obj is IAspectAware aspectAware)
            {
                aspectAware.OnCreated(joinpoint);
            }

            return(obj);
        }
Example #4
0
        public object WrapFlowScope(IJointPoint joinpoint)
        {
            var aspectType = typeof(TAspectType);
            var lifecycle  = PerCFlowAspectLifecycle.For(aspectType);

            lifecycle.Push(AspectRuntime.Provider.GetFactory(aspectType).CreateInstance(aspectType, joinpoint));
            try
            {
                return(joinpoint.Execute());
            }
            finally
            {
                lifecycle.Pop();
            }
        }
Example #5
0
 public object GetAspect(IJointPoint jointPoint)
 {
     if (!_isCreated)
     {
         lock (this)
         {
             if (!_isCreated)
             {
                 _instance  = _factory.CreateInstance(_type, jointPoint);
                 _isCreated = true;
             }
         }
     }
     return(_instance);
 }
Example #6
0
        public object GetAspect(IJointPoint jointPoint)
        {
            if (jointPoint.This == null)
            {
                return(null);
            }

            var aspect = ObjectBoundAspects.GetOrCreateValue(jointPoint.This).Get(_type);

            if (aspect == null && _autoInstantiate)
            {
                Bind(jointPoint, _type);
                aspect = ObjectBoundAspects.GetOrCreateValue(jointPoint.This).Get(_type);
            }
            return(aspect);
        }
Example #7
0
        public object CreateInstance(Type type, IJointPoint joinpoint)
        {
            MemberInfo member = null;

            if (joinpoint is ICallJointPoint callJp)
            {
                member = callJp.TargetMember;
            }

            if (joinpoint is IMemberJointPoint memberJp)
            {
                member = memberJp.Member;
            }

            return(member == null ? null : member.GetCustomAttributesData()
                   .Where(a => type.IsAssignableFrom(a.Constructor.ReflectedType))
                   .Select(ReflectionHelper.CreateAttribute)
                   .FirstOrDefault());
        }
Example #8
0
 public object Bind(IJointPoint jp)
 {
     PerThisAspectLifecycle.Bind(jp, typeof(TAspect));
     return(jp.Execute());
 }
Example #9
0
 public object GetAspect(IJointPoint jointPoint)
 {
     return(_factory(jointPoint));
 }
Example #10
0
 public static TAspect GetAspect <TAspect>(IJointPoint jointpoint)
 {
     return((TAspect)Provider.GetLifecycle(typeof(TAspect)).GetAspect(jointpoint));
 }
Example #11
0
 protected void Exit(IJointPoint jp, IInterception reset, object returnValue)
 {
 }
Example #12
0
 protected void Error(IJointPoint jp, IInterception reset, Exception exception)
 {
 }
Example #13
0
 protected void Success(IJointPoint jp, IInterception context, object returnValue)
 {
 }
Example #14
0
 public object Around(IJointPoint pointcut)
 {
     return(_uniqueId);
 }
Example #15
0
 public void StealNonTransactionalMethods(IJointPoint jp)
 {
     _nonTransactionalActions.Enqueue(() => jp.Execute());
 }
Example #16
0
 public object CreateInstance(Type type, IJointPoint joinpoint)
 {
     return(_container.GetInstance(type));
 }
Example #17
0
 public static void Bind(IJointPoint jp, Type aspectType)
 {
     ObjectBoundAspects.GetOrCreateValue(jp.This).Bind(aspectType, () => AspectRuntime.Provider.GetFactory(aspectType).CreateInstance(aspectType, jp));
 }
Example #18
0
        public object GetAspect(IJointPoint jointPoint)
        {
            var a = _threadStack.Value.Count == 0 ? null : _threadStack.Value.Peek();

            return(a);
        }