コード例 #1
0
        /// <summary>
        /// Resolves the specified abstract type.
        /// </summary>
        /// <param name="abstractType">Type of the abstract.</param>
        /// <param name="isProxy">if set to <c>true</c> [is proxy].</param>
        /// <returns>System.Object.</returns>
        /// <exception cref="System.Exception"></exception>
        /// <remarks>Rachistructure</remarks>
        private object Resolve(string registrationNames, bool isProxy)
        {
            if (_instanceMap.ContainsKey(registrationNames))
            {
                Type            concreteType             = _instanceMap[registrationNames];
                ConstructorInfo firstConstructor         = concreteType.GetConstructors()[0];
                ParameterInfo[] parameters               = firstConstructor.GetParameters();
                object          resolvedConcreteInstance = null;

                if (parameters.Length > 0)
                {
                    object[] resolvedParameters = new object[parameters.Length];

                    for (int i = 0; i < parameters.Length; i++)
                    {
                        ParameterInfo parameter     = parameters[i];
                        Type          parameterType = parameter.ParameterType;
                        // parametre türü nedir?
                        object parameterInstance = Resolve("parameterType", isProxy);
                        resolvedParameters[i] = parameterInstance;
                    }

                    resolvedConcreteInstance = firstConstructor.Invoke(resolvedParameters);
                }
                else
                {
                    resolvedConcreteInstance = Activator.CreateInstance(concreteType);
                }

                if (isProxy)
                {
                    object proxy = ProxyBuilder.CreateProxyObject(ProxyKind.RealProxy, concreteType, resolvedConcreteInstance);
                    return(proxy);
                }

                return(resolvedConcreteInstance);
            }

            throw new Exception(string.Format("{0} do not resolved because {1} not registered on this container!"));
        }