Exemple #1
0
        /// <summary>
        /// 执行方法
        /// </summary>
        /// <param name="extraArgs"></param>
        /// <exception cref="InvalidOperationException">实例不存在</exception>
        /// <exception cref="TargetInvocationException">方法执行时抛出异常</exception>
        /// <returns></returns>
        public object Invoke(Dictionary <string, object> extraArgs = null)
        {
            if (instance == null)
            {
                throw new InvalidOperationException("Please create instance before invoke method");
            }

            object[] args = ParameterArrayBuilder.BuildArgs(
                source,
                extraArgs ?? new Dictionary <string, object>(),
                method.GetParameters());

            object rawInvoker() => method.Invoke(instance, args);

            var aspects = GetAroundAspects();

            if (aspects.Any())
            {
                var aspectArgs = new AroundMethodArgs()
                {
                    MethodInfo = method,
                    Instance   = instance,
                    Args       = args,
                    ExtraArgs  = extraArgs,
                    Invoker    = rawInvoker
                };
                return(aspects.ElementAt(0).Around(aspectArgs));
            }
            else
            {
                return(rawInvoker());
            }
        }
Exemple #2
0
        public object Build(Dictionary <string, object> extraArgs = null)
        {
            var constructor = type.GetConstructors(ObjectManagementConstants.BINDING_FLAGS)[0];
            var args        = ParameterArrayBuilder.BuildArgs(
                source,
                extraArgs ?? new Dictionary <string, object>(), constructor.GetParameters());
            var instance = constructor.Invoke(args);

            new DependenciesInjector(instance, source).Inject();
            return(instance);
        }