Example #1
0
        private object GetInstance(RegisteredObject registeredObject)
        {
            if (registeredObject.Instance == null || registeredObject.LifeCycle == LifeCycle.Transient)
            {
                Type            implementation        = registeredObject.ConcreteType;
                ConstructorInfo constructor           = implementation.GetConstructors()[0];
                ParameterInfo[] constructorParameters = constructor.GetParameters();

                int      paramsLength = constructorParameters.Length;
                object[] parameters   = new object[paramsLength];
                if (paramsLength > 0)
                {
                    for (int i = 0; i < paramsLength; i++)
                    {
                        ParameterInfo parameterInfo = constructorParameters[i];
                        parameters[i] = Resolve(parameterInfo.ParameterType);
                    }
                }

                registeredObject.CreateInstance(parameters);
            }

            return(registeredObject.Instance);
        }