示例#1
0
        private IEnumerable <object> ResolveConstructorParameters(RegisteredObject registeredObject)
        {
            var constructors = registeredObject.ConcreteType.GetConstructors();

            if (constructors.Length == 0)
            {
                throw new ApplicationException("Constructor is not implemented or non-public in class " + registeredObject.ConcreteType.Name);
            }

            var constructorInfo = constructors[0];
            var result          = new List <object>();

            foreach (var parameter in constructorInfo.GetParameters())
            {
                result.Add(Resolve(parameter.ParameterType));
            }
            return(result);
        }
示例#2
0
        public object Resolve(Type typeToResolve)
        {
            RegisteredObject registeredObject = null;

            foreach (var obj in m_Objects)
            {
                if (obj.TypeToResolve == typeToResolve)
                {
                    registeredObject = obj;
                    break;
                }
            }

            if (registeredObject == null)
            {
                throw new TypeNotRegisteredException(string.Format(CultureInfo.InvariantCulture,
                                                                   "The type {0} has not been registered", typeToResolve.Name));
            }
            Debug.Print("IoC: Resolving {0} : {1}", registeredObject.ConcreteType.Name, typeToResolve.Name);
            return(GetInstance(registeredObject));
        }