示例#1
0
        /// <summary>
        /// Resolve constructor parameters for the Implementation type <see cref="RegisteredObject"/>
        /// </summary>
        /// <param name="registeredObject"><see cref="RegisteredObject"/></param>
        /// <returns><see cref="IEnumerable{T}"/> of the constructor parameters</returns>
        /// <exception cref="InvalidOperationException">If the <see cref="RegisteredObject.ConcreteType"/> does not have a public constructor</exception>
        private IEnumerable <object> ResolveConstructorParameters(RegisteredObject registeredObject)
        {
            //TODO: Currently support only Public Ctor types. In Future add other types e.g.:internal
            var constructorInfo = registeredObject.ConcreteType.GetConstructors().FirstOrDefault();

            if (constructorInfo == null)
            {
                throw new InvalidOperationException($"A public constructor not found for {registeredObject.ConcreteType.FullName}");
            }

            foreach (var parameter in constructorInfo.GetParameters())
            {
                yield return(ResolveObject(parameter.ParameterType));
            }
        }
示例#2
0
 /// <summary>
 /// Check if the instance exists in the store for <see cref="RegisteredObject.InterfaceType"/>
 /// </summary>
 /// <param name="regObject">Type of <see cref="RegisteredObject"/></param>
 /// <returns>True if found</returns>
 public bool IsRegistered(RegisteredObject regObject)
 {
     return(_lifecycleStores[regObject.Lifecycle].IsRegistered(regObject));
 }
示例#3
0
 /// <summary>
 /// Get instance of <see cref="RegisteredObject.InterfaceType"/>
 /// </summary>
 /// <param name="regObject">Type of <see cref="RegisteredObject"/></param>
 /// <returns>The instance from the store or null if not found </returns>
 public object GetInstance(RegisteredObject regObject)
 {
     return(_lifecycleStores[regObject.Lifecycle].GetInstance(regObject));
 }
示例#4
0
 /// <summary>
 /// Create an instance of <see cref="RegisteredObject.ConcreteType"/> and store it depending on <see cref="LifecycleType"/> for the instance
 /// </summary>
 /// <param name="regObject">Type of <see cref="RegisteredObject"/></param>
 /// <param name="args"><see cref="RegisteredObject.ConcreteType"/> constructor arguments</param>
 /// <returns>Instance of <see cref="RegisteredObject.ConcreteType"/></returns>
 public object CreateInstance(RegisteredObject regObject, params object[] args)
 {
     return(_lifecycleStores[regObject.Lifecycle].CreateInstance(regObject, args));
 }