private IEnumerable <object> ResolveConstructorParameters(RegisteredObject registeredObject) { var constructorInfo = registeredObject.ConcreteType.GetConstructors().First(); if (constructorInfo == null) { throw new Exception($"There are no public constructors for type {registeredObject.ConcreteType.FullName}"); } return(constructorInfo.GetParameters().Select(parameter => ResolveObject(parameter.ParameterType))); }
private object GetInstance(RegisteredObject registeredObject) { object instance = registeredObject.SingletonInstance; if (instance != null) { return(instance); } var isConstructorAttribute = registeredObject.ConcreteType.GetCustomAttribute <ImportConstructorAttribute>(false) != null; if (isConstructorAttribute) { var parameters = ResolveConstructorParameters(registeredObject); instance = registeredObject.CreateInstance(parameters.ToArray()); } else { instance = registeredObject.CreateInstance(); ResolveProperty(registeredObject, ref instance); } return(instance); }