示例#1
0
        public object ResolveMany(Type contractType, InjectContext context)
        {
            // Note that different types can map to the same provider (eg. a base type to a concrete class and a concrete class to itself)

            var matches = GetProviderMatchesInternal(contractType, context).ToList();

            if (matches.Any())
            {
                return(ReflectionUtil.CreateGenericList(
                           contractType, matches.Select(x => x.GetInstance(contractType, context)).ToArray()));
            }

            if (!context.Optional)
            {
                if (_fallbackProvider != null)
                {
                    var listType = typeof(List <>).MakeGenericType(contractType);

                    return(_fallbackProvider.GetInstance(listType, context));
                }

                throw new ZenjectResolveException(
                          "Could not find required dependency with type '" + contractType.Name() + "' \nObject graph:\n" + GetCurrentObjectGraph());
            }

            return(ReflectionUtil.CreateGenericList(contractType, new object[] {}));
        }
示例#2
0
        public object ResolveMany(Type contract, ResolveContext context, bool optional, bool soft)
        {
            Assert.That(!_hasDisposed);
            // Note that different types can map to the same provider (eg. a base type to a concrete class and a concrete class to itself)

            var matches = ResolveInternalList(contract, context, soft);

            if (matches.Any())
            {
                return(ReflectionUtil.CreateGenericList(
                           contract, matches.ToArray()));
            }

            if (!optional)
            {
                throw new ZenjectResolveException(
                          "Could not find required dependency with type '" + contract.Name() + "' \nObject graph:\n" + GetCurrentObjectGraph());
            }

            return(ReflectionUtil.CreateGenericList(contract, new object[] {}));
        }