Example #1
0
        private ServiceDescriptor TryToDiscover(Type serviceType)
        {
            if (EnumerableStep.IsEnumerable(serviceType))
            {
                return(null);
            }

            if (serviceType.IsGenericType)
            {
                var basicType = serviceType.GetGenericTypeDefinition();



                var templatedParameterTypes = serviceType.GetGenericArguments();
                var candidates = _services.Where(x => x.ServiceType == basicType && x.ImplementationType != null).Select(x =>
                {
                    return(new ServiceDescriptor(serviceType, x.ImplementationType.MakeGenericType(templatedParameterTypes), x.Lifetime));
                }).ToArray();

                _services.AddRange(candidates);

                if (candidates.Any())
                {
                    return(candidates.LastOrDefault());
                }
            }

            if (serviceType.IsConcrete() && !serviceType.IsGenericTypeDefinition && ChooseConstructor(serviceType) != null)
            {
                return(new ServiceDescriptor(serviceType, serviceType, ServiceLifetime.Transient));
            }

            return(null);
        }
Example #2
0
        public ListAssignmentFrame(Type serviceType, Variable[] elements) : base(false)
        {
            ElementType = EnumerableStep.DetermineElementType(serviceType);
            Variable    = new Variable(serviceType, Variable.DefaultArgName(ElementType) + "List", this);

            Elements = elements;
        }
Example #3
0
        private BuildStep findStep(Type type)
        {
            // INSTEAD, let's pull all variable sources
            // If not a ServiceVariable, use the KnownVariableBuildStep, otherwise use the
            // parent build step and do NOT visit its dependencies
            var variable = _method.TryFindVariable(type, VariableSource.NotServices);

            if (variable != null)
            {
                return(new KnownVariableBuildStep(variable));
            }

            var @default = _graph.FindDefault(type);

            if (@default == null)
            {
                if (EnumerableStep.IsEnumerable(type))
                {
                    return(tryFillEnumerableOfAllKnown(type));
                }

                return(null);
            }

            return(findStep(@default));
        }
Example #4
0
        private BuildStep tryFillEnumerableOfAllKnown(Type serviceType)
        {
            var elementType = EnumerableStep.DetermineElementType(serviceType);
            var all         = _graph.FindAll(elementType);

            if (!all.All(x => _graph.CanResolve(x)))
            {
                return(null);
            }

            var childSteps = all.Select(FindStep).ToArray();

            return(new EnumerableStep(serviceType, childSteps));
        }