Exemple #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);
        }
        public object Construct(ConstruktionContext requestContext)
        {
            var blueprint = _blueprints.First(x => x.Matches(requestContext));

            var result = construct(requestContext, blueprint);

            return(result);
        }
Exemple #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);
        }
        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);
        }
Exemple #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;
Exemple #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);
Exemple #7
0
 /// <inheritdoc />
 object Blueprint.Construct(ConstruktionContext context, ConstruktionPipeline pipeline) => Construct(context, pipeline);
Exemple #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;
Exemple #9
0
 /// <inheritdoc />
 bool Blueprint.Matches(ConstruktionContext context) => context.RequestType == typeof(T) && Matches(context);
Exemple #10
0
 public bool Matches(object item, ConstruktionContext context) =>
 typeof(T).IsAssignableFrom(context.RequestType) && Matches((T)item, context);