Ejemplo n.º 1
0
        /// <summary>
        /// Construct a parameter using its attribute's value.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="pipeline"></param>
        /// <returns></returns>
        public virtual object Construct(ConstruktionContext context, ConstruktionPipeline pipeline)
        {
            var attribute = (T)context.ParameterInfo.GetCustomAttribute(typeof(T));

            var value = _value(attribute);

            return(value);
        }
Ejemplo n.º 2
0
        public object Construct(ConstruktionContext requestContext)
        {
            var blueprint = _blueprints.First(x => x.Matches(requestContext));

            var result = construct(requestContext, blueprint);

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get detailed log information about the way Construktion is constructing your objects. DO NOT use for normal operations. Should be used for ad hoc debugging only.
        /// </summary>
        /// <returns></returns>
        public object DebuggingConstruct(ConstruktionContext context, out string log)
        {
            var pipeline = new DebuggingConstruktionPipeline(_settings);

            var result = pipeline.DebugSend(context, out List <string> debugLog);

            log = string.Join("\n", debugLog);

            return(result);
        }
Ejemplo n.º 4
0
        private object construct(ConstruktionContext requestContext, Blueprint blueprint)
        {
            if (_recurssionGuard.Contains(requestContext.RequestType))
            {
                return(default(object));
            }

            _recurssionGuard.Add(requestContext.RequestType);

            var result = blueprint.Construct(requestContext, this);

            _recurssionGuard.Remove(requestContext.RequestType);

            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// The base implementation returns true if the parameter has the attribute.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public virtual bool Matches(ConstruktionContext context) => context.ParameterInfo?.GetCustomAttributes(typeof(T))
 .ToList()
 .Any() ?? false;
Ejemplo n.º 6
0
 /// <summary>
 /// Construct an object of T.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="pipeline"></param>
 /// <returns></returns>
 public abstract T Construct(ConstruktionContext context, ConstruktionPipeline pipeline);
Ejemplo n.º 7
0
 /// <inheritdoc />
 object Blueprint.Construct(ConstruktionContext context, ConstruktionPipeline pipeline) => Construct(context, pipeline);
Ejemplo n.º 8
0
 /// <summary>
 /// Matches types of the closed generic. Can be overridden in derived classes.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public virtual bool Matches(ConstruktionContext context) => true;
Ejemplo n.º 9
0
 /// <inheritdoc />
 bool Blueprint.Matches(ConstruktionContext context) => context.RequestType == typeof(T) && Matches(context);
Ejemplo n.º 10
0
 public bool Matches(object item, ConstruktionContext context) =>
 typeof(T).IsAssignableFrom(context.RequestType) && Matches((T)item, context);