Esempio n. 1
0
    protected override IConstructorArgument[] GetConstructorArguments(MethodInfo methodInfo, object[] arguments)
    {
        var parameters = methodInfo.GetParameters();
        var constructorArgumentArray = new IConstructorArgument[parameters.Length];

        for (var i = 0; i < parameters.Length; ++i)
        {
            constructorArgumentArray[i] = new ConstructorArgument(parameters[i].Name, arguments[i], _parametersToInherit.Contains(parameters[i].Name));
        }
        return(constructorArgumentArray);
    }
    protected override IConstructorArgument[] GetConstructorArguments(MethodInfo methodInfo, object[] arguments)
    {
        var parameters           = methodInfo.GetParameters();
        var constructorArguments = new IConstructorArgument[parameters.Length];

        for (int i = 0; i < parameters.Length; i++)
        {
            constructorArguments[i] = new ConstructorArgument(parameters[i].Name, arguments[i], true);
        }
        return(constructorArguments);
    }
Esempio n. 3
0
        /// <summary>
        /// Gets the constructor arguments that shall be passed with the instance request. Created constructor arguments are flagged as inherited
        /// and are of type TypeMatchingConstructorArgument
        /// </summary>
        /// <param name="methodInfo">The method info of the method that was called on the factory.</param>
        /// <param name="arguments">The arguments that were passed to the factory.</param>
        /// <returns>The constructor arguments that shall be passed with the instance request.</returns>
        protected override IConstructorArgument[] GetConstructorArguments(MethodInfo methodInfo, object[] arguments)
        {
            ParameterInfo[]        parameters           = methodInfo.GetParameters();
            IConstructorArgument[] constructorArguments = new IConstructorArgument[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                int closure = i;
                constructorArguments[i] = new TypeMatchingConstructorArgument(parameters[i].ParameterType, (context, target) => arguments[closure], true);
            }

            return(constructorArguments);
        }
        /// <summary>
        /// Gets the constructor arguments that shall be passed with the instance request. Created constructor arguments are flagged as inherited 
        /// and are of type TypeMatchingConstructorArgument
        /// </summary>
        /// <param name="methodInfo">The method info of the method that was called on the factory.</param>
        /// <param name="arguments">The arguments that were passed to the factory.</param>
        /// <returns>The constructor arguments that shall be passed with the instance request.</returns>
        protected override IConstructorArgument[] GetConstructorArguments(MethodInfo methodInfo, object[] arguments)
        {
            ParameterInfo[] parameters = methodInfo.GetParameters();
            IConstructorArgument[] constructorArguments = new IConstructorArgument[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                int closure = i;
                constructorArguments[i] = new TypeMatchingConstructorArgument(parameters[i].ParameterType, (context, target) => arguments[closure], true);
            }

            return constructorArguments;
        }
        /// <summary>
        /// Gets an instance of the specified type.
        /// </summary>
        /// <param name="type">The type of the instance.</param>
        /// <param name="name">The name of the binding to use. If null the name is not used.</param>
        /// <param name="constraint">The constraint for the bindings. If null the constraint is not used.</param>
        /// <param name="constructorArguments">The constructor arguments.</param>
        /// <param name="fallback">if set to <c>true</c> the request fallsback to requesting instances without
        /// name or constraint if no one can received otherwise.</param>
        /// <returns>An instance of the specified type.</returns>
        public object Get(Type type, string name, Func<IBindingMetadata, bool> constraint, IConstructorArgument[] constructorArguments, bool fallback)
        {
            if (fallback && constraint != null)
            {
                return this.resolutionRoot.TryGet(type, constraint, constructorArguments) ??
                       this.Get(type, name, null, constructorArguments, true);
            }

            if (fallback && name != null)
            {
                return this.resolutionRoot.TryGet(type, name, constructorArguments) ??
                       this.Get(type, null, null, constructorArguments, true);
            }

            return constraint == null
                       ? name == null
                             ? this.resolutionRoot.Get(type, constructorArguments)
                             : this.resolutionRoot.Get(type, name, constructorArguments)
                       : this.resolutionRoot.Get(type, constraint, constructorArguments);
        }
Esempio n. 6
0
        private static object GetValueCore(IContext context, ITarget target)
        {
            IConstructorArgument constructorArgument = null;

            foreach (var parameter in context.Parameters)
            {
                if (parameter is IConstructorArgument ctorArg && ctorArg.AppliesToTarget(context, target))
                {
                    if (constructorArgument != null)
                    {
                        throw new InvalidOperationException("Sequence contains more than one matching element");
                    }

                    constructorArgument = ctorArg;
                }
            }

            if (constructorArgument != null)
            {
                return(constructorArgument.GetValue(context, target));
            }

            return(target.ResolveWithin(context));
        }
 public DependsOnMultipleInterface(IConstructorArgument argument1, IConstructorArgument argument2)
 {
     this.argument1 = argument1;
     this.argument2 = argument2;
 }
Esempio n. 8
0
 public ResolvedGenericConstructorArgument(IConstructorArgument ca, Func <IDataType> actualType) : base(ca, actualType)
 {
     _ca = ca;
 }
Esempio n. 9
0
 public DependsOnInterface(IConstructorArgument argument)
 {
     this.argument = argument;
 }
 public DependsOnAlternateConstructorImplicitly(IConstructorArgument argument)
 {
     this.argument = argument;
 }
 public DependsOnMultipleInterface(IConstructorArgument argument1, IConstructorArgument argument2)
 {
     this.argument1 = argument1;
     this.argument2 = argument2;
 }
        /// <summary>
        /// Gets all instances that match the specified parameters.
        /// </summary>
        /// <param name="type">The type of the instance.</param>
        /// <param name="name">The name of the binding to use. If null the name is not used.</param>
        /// <param name="constraint">The constraint for the bindings. If null the constraint is not used.</param>
        /// <param name="constructorArguments">The constructor arguments.</param>
        /// <param name="fallback">if set to <c>true</c> the request fallsback to requesting instances without
        /// name or constraint if no one can received otherwise.</param>
        /// <returns>All instances of the specified type.</returns>
        private IEnumerable<object> GetAll(Type type, string name, Func<IBindingMetadata, bool> constraint, IConstructorArgument[] constructorArguments, bool fallback)
        {
            if (fallback && constraint != null)
            {
                var result = this.resolutionRoot.GetAll(type, constraint, constructorArguments);
                return result.Any() ? result : this.GetAll(type, name, null, constructorArguments, true);
            }

            if (fallback && name != null)
            {
                var result = this.resolutionRoot.GetAll(type, name, constructorArguments);
                return result.Any() ? result : this.GetAll(type, null, null, constructorArguments, true);
            }

            return constraint == null
                       ? name == null
                             ? this.resolutionRoot.GetAll(type, constructorArguments)
                             : this.resolutionRoot.GetAll(type, name, constructorArguments)
                       : this.resolutionRoot.GetAll(type, constraint, constructorArguments);
        }
 /// <summary>
 /// Gets all instances of the specified type as array.
 /// </summary>
 /// <param name="type">The type of the instance.</param>
 /// <param name="name">The name of the binding to use. If null the name is not used.</param>
 /// <param name="constraint">The constraint for the bindings. If null the constraint is not used.</param>
 /// <param name="constructorArguments">The constructor arguments.</param>
 /// <param name="fallback">if set to <c>true</c> the request fallsback to requesting instances without
 /// name or constraint if no one can received otherwise.</param>
 /// <returns>An instance of the specified type.</returns>
 public object GetAllAsArray(Type type, string name, Func<IBindingMetadata, bool> constraint, IConstructorArgument[] constructorArguments, bool fallback)
 {
     var list = this.GetAllAsList(type, name, constraint, constructorArguments, fallback);
     return typeof(Enumerable)
         .GetMethod("ToArray")
         .MakeGenericMethod(type)
         .Invoke(null, new[] { list });
 }
 public DependsOnAlternateConstructorImplicitly(IConstructorArgument argument)
 {
     this.argument = argument;
 }
Esempio n. 15
0
 public DependsOnMultipleInterfaceTypes(IConstructorArgument arg, IServiceLocator locator)
 {
     this.arg     = arg;
     this.locator = locator;
 }
Esempio n. 16
0
 public TestCase4(IConstructorArgument argument)
 {
     this.argument = argument;
 }
        /// <summary>
        /// Gets all instances of the specified type as list.
        /// </summary>
        /// <param name="type">The type of the instance.</param>
        /// <param name="name">The name of the binding to use. If null the name is not used.</param>
        /// <param name="constraint">The constraint for the bindings. If null the constraint is not used.</param>
        /// <param name="constructorArguments">The constructor arguments.</param>
        /// <param name="fallback">if set to <c>true</c> the request fallsback to requesting instances without
        /// name or constraint if no one can received otherwise.</param>
        /// <returns>An instance of the specified type.</returns>
        public object GetAllAsList(Type type, string name, Func<IBindingMetadata, bool> constraint, IConstructorArgument[] constructorArguments, bool fallback)
        {
            var listType = typeof(List<>).MakeGenericType(type);
            var list = listType.GetConstructor(new Type[0]).Invoke(new object[0]);
            var addMethod = listType.GetMethod("Add");

            var values = this.GetAll(type, name, constraint, constructorArguments, fallback);

            foreach (var value in values)
            {
                addMethod.Invoke(list, new[] { value });
            }

            return list;
        }
Esempio n. 18
0
 public TestCase4(IConstructorArgument argument)
 {
     this.argument = argument;
 }
Esempio n. 19
0
 public DependsOnInterface(IConstructorArgument argument)
 {
     this.argument = argument;
 }
 public DependsOnMultipleInterfaceTypes(IConstructorArgument arg, IServiceLocator locator)
 {
     this.arg = arg;
     this.locator = locator;
 }
 public TestableStandardInstanceProvider(
     Func<Planning.Bindings.IBindingMetadata, bool> constraint,
     string name,
     IConstructorArgument[] constructorArguments,
     object[] expectedArguments)
 {
     this.constraint = constraint;
     this.name = name;
     this.constructorArguments = constructorArguments;
     this.expectedArguments = expectedArguments;
 }