Beispiel #1
0
        public override IEnumerable <Expression> Express(ref PipelineBuilder builder)
        {
            if (!builder.IsMapping)
            {
                return(builder.Express());
            }

            var requestedType = builder.Type;

            if (null != builder.Registration)
            {
                // Explicit Registration
                if (null == builder.Registration.Type)
                {
                    return(builder.Express());
                }

                builder.Type = builder.Registration.Type;
            }
            else if (null != builder.TypeConverter)
            {
                builder.Type = builder.TypeConverter(builder.Type);
            }

            // If nothing to map or build required, just create it
            if (builder.BuildRequired || requestedType == builder.Type)
            {
                return(builder.Express());
            }

            var type = builder.Type;

            return(builder.Express((ref PipelineContext context) => context.Resolve(type)));
        }
        public override ResolveDelegate <BuilderContext>?Build(ref PipelineBuilder builder)
        {
            var requestedType = builder.Type;

            if (builder.Policies is ExplicitRegistration registration)
            {
                // Explicit Registration
                if (null == registration.Type)
                {
                    return(builder.Pipeline());
                }

                builder.Type = (null == registration.BuildType)
                    ? registration.Type
                    : registration.BuildType(registration.Type);
            }
            else
            {
                // Implicit Registration
                if (null != builder.TypeConverter)
                {
                    builder.Type = builder.TypeConverter(builder.Type);
                }
            }

            // If nothing to map or build required, just create it
            if (builder.BuildRequired || requestedType == builder.Type)
            {
                return(builder.Pipeline());
            }

            var type = builder.Type;

            return(builder.Pipeline((ref BuilderContext context) =>
            {
                try
                {
                    return context.Resolve(type);
                }
                catch (Exception ex)
                {
                    ex.Data.Add(Guid.NewGuid(), new Tuple <Type, Type>(requestedType, type));
                    throw;
                }
            }));
        }