Esempio n. 1
0
        public static ConstructorStep BuildConstructorStep(Type pluggedType, ConstructorInfo constructor,
                                                           DependencyCollection dependencies, Policies policies)
        {
            var ctor = constructor ?? policies.SelectConstructor(pluggedType, dependencies);

            if (ctor == null)
            {
                throw new StructureMapConfigurationException(
                          "No public constructor could be selected for concrete type " + pluggedType.GetFullName());
            }

            var ctorStep  = new ConstructorStep(ctor);
            var multiples = findTypesWithMultipleParametersRequired(ctor);

            var ctorDependencies = ctor
                                   .GetParameters()
                                   .Select(x => {
                var dependency = multiples.Contains(x.ParameterType)
                        ? dependencies.FindByTypeAndName(x.ParameterType, x.Name)
                        : dependencies.FindByTypeOrName(x.ParameterType, x.Name);

                if (dependency == null && ((x.DefaultValue != null && x.DefaultValue.GetType().Name != "DBNull")))
                {
                    dependency = x.DefaultValue;
                }

                return(SourceFor(ConstructorArgument, x.Name, x.ParameterType, dependency));
            });

            ctorStep.Add(ctorDependencies);

            return(ctorStep);
        }
Esempio n. 2
0
        public static ConstructorStep BuildConstructorStep(Type pluggedType, ConstructorInfo constructor,
            DependencyCollection dependencies, Policies policies)
        {
            var ctor = constructor ?? policies.SelectConstructor(pluggedType);
            if (ctor == null)
            {
                throw new StructureMapConfigurationException(
                    "No public constructor could be selected for concrete type " + pluggedType.GetFullName());
            }

            var ctorStep = new ConstructorStep(ctor);
            var multiples = findTypesWithMultipleParametersRequired(ctor);

            var ctorDependencies = ctor
                .GetParameters()
                .Select(x => {
                    var dependency = multiples.Contains(x.ParameterType)
                        ? dependencies.FindByTypeAndName(x.ParameterType, x.Name)
                        : dependencies.FindByTypeOrName(x.ParameterType, x.Name);

                    if (dependency == null && ( (x.DefaultValue != null && x.DefaultValue.GetType().Name != "DBNull")))
                    {
                        dependency = x.DefaultValue;
                    }

                    return SourceFor(ConstructorArgument, x.Name, x.ParameterType, dependency);
                });

            ctorStep.Add(ctorDependencies);

            return ctorStep;
        }
Esempio n. 3
0
        public void Constructor(ConstructorStep constructor)
        {
            _writer.Line(constructor.Description);
            if (constructor.Arguments.Any())
            {
                _writer.StartSection<Outline>();

                constructor.Arguments.Each(arg => {
                    using (var depVisualizer = new DependencyVisualizer(arg.Title, _writer, this))
                    {
                        arg.Dependency.AcceptVisitor(depVisualizer);
                    }
                });

                _writer.EndSection();
            }

        }
Esempio n. 4
0
 public ConcreteBuild(Type concreteType, ConstructorStep constructor)
 {
     _concreteType = concreteType;
     _constructor  = constructor;
 }
 public void Constructor(ConstructorStep constructor)
 {
     Items.Add("Constructor: " + constructor.Constructor);
 }