/// <summary> /// "Builds" values for parameters by building a set of <see cref="UnitInfo" />(<paramref name="parameters" />[i], <see cref="SpecialToken.InjectValue" />) /// one by one via current build session /// </summary> public static object[] GetValuesForParameters([NotNull] this IBuildSession buildSession, [NotNull] ParameterInfo[] parameters) { if (buildSession == null) { throw new ArgumentNullException(nameof(buildSession)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (parameters.Length == 0) { throw new ArgumentException("At least one parameters should be provided", nameof(parameters)); } var values = new object[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { var buildResult = buildSession.BuildUnit(new UnitInfo(parameters[i], SpecialToken.InjectValue)); if (!buildResult.HasValue) { throw new ArmatureException(string.Format("Can't build value for parameter {0}", parameters[i])); } values[i] = buildResult.Value; } return(values); }
/// <summary> /// Builds an argument to inject into the property representing by <paramref name="propertyInfo" /> /// </summary> public static object?BuildPropertyArgument(this IBuildSession buildSession, PropertyInfo propertyInfo) { var buildResult = buildSession.BuildUnit(new UnitId(propertyInfo, SpecialTag.Argument)); return(buildResult.HasValue ? buildResult.Value : throw new ArmatureException(string.Format("Argument for property '{0}' of {1} is not built", propertyInfo, propertyInfo.DeclaringType))); }
public void Process(IBuildSession buildSession) { var unitUnderConstruction = buildSession.GetUnitUnderConstruction(); var effectiveToken = Equals(_token, Token.Propagate) ? unitUnderConstruction.Token : _token; var genericType = _redirectTo.MakeGenericType(buildSession.GetUnitUnderConstruction().GetUnitType().GetGenericArguments()); buildSession.BuildResult = buildSession.BuildUnit(new UnitInfo(genericType, effectiveToken)); }
public void Process(IBuildSession buildSession) { if (!buildSession.BuildResult.HasValue) { var unitUnderConstruction = buildSession.GetUnitUnderConstruction(); var effectiveToken = Equals(_token, Token.Propagate) ? unitUnderConstruction.Token : _token; var unitInfo = new UnitInfo(_redirectTo, effectiveToken); buildSession.BuildResult = buildSession.BuildUnit(unitInfo); } }
public static object?[] BuildArgumentsForMethod(this IBuildSession buildSession, ParameterInfo[] parameters) { if (buildSession is null) { throw new ArgumentNullException(nameof(buildSession)); } if (parameters is null) { throw new ArgumentNullException(nameof(parameters)); } if (parameters.Length == 0) { throw new ArgumentException("At least one parameter should be provided", nameof(parameters)); } return((object?[])buildSession.BuildUnit(new UnitId(parameters, SpecialTag.Argument)).Value !); }
public void Process(IBuildSession buildSession) { var propertyInfo = (PropertyInfo)buildSession.GetUnitUnderConstruction().Id; var attribute = propertyInfo .GetCustomAttributes <InjectAttribute>() .SingleOrDefault(); if (attribute == null) { Log.WriteLine(LogLevel.Info, () => string.Format("{0}{{{1}}}", this, "No Property marked with InjectAttribute")); } else { var unitInfo = new UnitInfo(propertyInfo.PropertyType, attribute.InjectionPointId); buildSession.BuildResult = buildSession.BuildUnit(unitInfo); } }
/// <summary> /// "Builds" a <see cref="ConstructorInfo" /> for a <see creaf="type" /> by building a unit represented /// by <see cref="UnitInfo" />(<paramref name="type" />, <see cref="SpecialToken.Constructor" />) via current build session. /// </summary> public static ConstructorInfo GetConstructorOf([NotNull] this IBuildSession buildSessoin, [NotNull] Type type) { if (buildSessoin == null) { throw new ArgumentNullException(nameof(buildSessoin)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } var result = buildSessoin.BuildUnit(new UnitInfo(type, SpecialToken.Constructor)); if (!result.HasValue) { throw new Exception(string.Format("Can't find appropriate constructor for type {0}", type)); } return((ConstructorInfo)result.Value); }
/// <summary> /// Builds a <see cref="ConstructorInfo" /> for a <see creaf="type" /> by building a unit represented /// by <see cref="UnitId" />(<paramref name="type" />, <see cref="SpecialTag.Constructor" />) via current build session. /// </summary> public static ConstructorInfo GetConstructorOf(this IBuildSession buildSession, Type type) { if (buildSession is null) { throw new ArgumentNullException(nameof(buildSession)); } if (type is null) { throw new ArgumentNullException(nameof(type)); } var result = buildSession.BuildUnit(new UnitId(type, SpecialTag.Constructor)); if (!result.HasValue) { throw new ArmatureException($"Constructor for type {type} is not found, check registrations for this type or 'default' registrations."); } return((ConstructorInfo)result.Value !); }
/// <summary> /// "Builds" a value to inject into the property representing by <paramref name="propertyInfo" /> /// </summary> public static object GetValueForProperty(this IBuildSession buildSession, PropertyInfo propertyInfo) { var buildResult = buildSession.BuildUnit(new UnitInfo(propertyInfo, SpecialToken.InjectValue)); return(buildResult.HasValue ? buildResult.Value : throw new ArmatureException(string.Format("Can't build value for property {0}", propertyInfo))); }