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?.ImplementationType != null)
            {
                var ctor = _graph.ChooseConstructor(@default.ImplementationType);
                if (ctor != null)
                {
                    return(new ConstructorBuildStep(type, @default.ImplementationType, @default.Lifetime, ctor));
                }
            }

            // TODO -- split on T[], IList<T>, IEnumerable<T>, IReadOnlyList<T>

            return(null);
        }
Example #2
0
        private BuildStep findStep(ServiceDescriptor descriptor)
        {
            if (descriptor?.ImplementationType != null)
            {
                var ctor = _graph.ChooseConstructor(descriptor.ImplementationType);
                if (ctor != null)
                {
                    return(new ConstructorBuildStep(descriptor, ctor));
                }
            }

            return(null);
        }
Example #3
0
        private BuildStep findStep(Type type)
        {
            var variable = _method.TryFindVariable(type, VariableSource.All);

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

            var @default = _graph.FindDefault(type);

            if (@default?.ImplementationType != null)
            {
                var ctor = _graph.ChooseConstructor(@default.ImplementationType);
                if (ctor != null)
                {
                    return(new ConstructorBuildStep(type, @default.ImplementationType, @default.Lifetime, ctor));
                }
            }

            // split on T[], IList<T>, IEnumerable<T>, IReadOnlyList<T>

            return(null);
        }
Example #4
0
        public BuildStepPlanner(Type serviceType, Type concreteType, ServiceGraph graph, IMethodVariables method)
        {
            if (!concreteType.IsConcrete())
            {
                throw new ArgumentOutOfRangeException(nameof(concreteType), "Must be a concrete type");
            }

            ConcreteType = concreteType;
            _graph       = graph;
            _method      = method;


            var ctor = graph.ChooseConstructor(concreteType);

            if (ctor == null)
            {
                CanBeReduced = false;
            }
            else
            {
                Top = new ConstructorBuildStep(serviceType, concreteType, ServiceLifetime.Scoped, ctor);
                Visit(Top);
            }
        }