Exemple #1
0
        public object CreateObject(IContainer owner)
        {
            object[]        ctorParams         = new object[this.CtorParameterConfigurations.Count];
            ParameterInfo[] ctorParameterInfos = this.Constructor.GetParameters();
            for (int i = 0; i < ctorParams.Length; i++)
            {
                ParameterConfiguration paramConfig = (ParameterConfiguration)this.CtorParameterConfigurations[i];
                paramConfig.Type = ctorParameterInfos[i].ParameterType;

                object res = paramConfig.GetValue(owner);
                ctorParams[i] = res;
            }
            object instance = null;

            try
            {
                instance = owner.ObjectFactory.CreateInstance(aopEngine, this.Type, ctorParams);
                LogMessage message = new LogMessage("Creating instance of type '{0}' from config '{1}'", this.Type, this.Name);
                owner.LogManager.Info(this, message);
            }
            catch
            {
                LogMessage message = new LogMessage("Failed to create instance of type '{0}' from config '{1}'", this.Type, this.Name);
                owner.LogManager.Fatal(this, message);

                throw;
            }


            return(instance);
        }
Exemple #2
0
        public object Invoke(IContainer owner, Type requestedType, InstanceMode instanceMode)
        {
            object[]        parameters     = new object[ParameterConfigurations.Count];
            ParameterInfo[] parameterInfos = method.GetParameters();
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterConfiguration paramConfig = (ParameterConfiguration)ParameterConfigurations[i];
                paramConfig.Type = parameterInfos[i].ParameterType;
                parameters[i]    = paramConfig.GetValue(owner);
            }


            object target = null;

            if (Object != null)
            {
                target = owner.GetObject(Object.Name);
            }

            object res = method.Invoke(target, parameters);

            return(res);
        }