/// <summary> /// Instantiate a Unit using a constructor with the biggest number of parameters /// </summary> public Tuner UsingLongestConstructor() { UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(new LastUnitSequenceMatcher(ConstructorMatcher.Instance)) .AddBuildAction(BuildStage.Create, GetLongestConstructorBuildAction.Instance); return(this); }
/// <summary> /// Provided values will be used to inject the into created object. See <see cref="ForParameter" /> for details /// </summary> public Tuner UsingParameters(params object[] values) { if (values == null || values.Length == 0) { throw new Exception("null"); } foreach (var parameter in values) { if (parameter is IParameterValueBuildPlan buildPlan) { buildPlan.Apply(UnitSequenceMatcher); } else if (parameter is IBuildPlan) { throw new ArmatureException("IParameterValueBuildPlan or plain object value expected"); } else { UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(new LastUnitSequenceMatcher(new ParameterByValueMatcher(parameter), InjectPointMatchingWeight.WeakTypedParameter)) .AddBuildAction(BuildStage.Create, new SingletonBuildAction(parameter)); } } return(this); }
/// <summary> /// Instantiate a Unit using a constructor marked with <see cref="InjectAttribute" />(<paramref name="injectionPointId" />) /// </summary> public Tuner UsingInjectPointConstructor(object injectionPointId) { UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(new LastUnitSequenceMatcher(ConstructorMatcher.Instance)) .AddBuildAction(BuildStage.Create, new GetInjectPointConstructorBuildAction(injectionPointId)); return(this); }
/// <summary> /// Instantiate a Unit using constructor with exact set of parameters as provided in <paramref name="parameterTypes" /> /// </summary> public Tuner UsingConstructorWithParameters(params Type[] parameterTypes) { UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(new LastUnitSequenceMatcher(ConstructorMatcher.Instance)) .AddBuildAction(BuildStage.Create, new GetConstructorByParameterTypesBuildAction(parameterTypes)); return(this); }
/// <summary> /// Specifies that unit of type passed into <see cref="TreatingTuner{T}.As(System.Type,object)"/> or <see cref="TreatingTuner{T}.As{TRedirect}"/> should /// be created using reflection /// </summary> /// <returns></returns> public Tuner CreatedByReflection() { var sequenceMatcher = new StrictUnitSequenceMatcher(Match.Type(Type, Token)); UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(sequenceMatcher) .AddBuildAction(BuildStage.Create, CreateByReflectionBuildAction.Instance); return(new Tuner(sequenceMatcher)); }
/// <summary> /// Specifies that unit of type passed into <see cref="TreatingTuner{T}.As(System.Type,object)"/> or <see cref="TreatingTuner{T}.As{TRedirect}"/> /// should be created using default creation strategy specified in <see cref="Default.CreationBuildAction" /> /// </summary> public Tuner CreatedByDefault() { var sequenceMatcher = new StrictUnitSequenceMatcher(Match.Type(Type, Token)); UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(sequenceMatcher) .AddBuildAction(BuildStage.Create, Default.CreationBuildAction); return(new Tuner(sequenceMatcher)); }
public Tuner CreatedByReflection() { var childMatcher = new WildcardUnitSequenceMatcher(Match.OpenGenericType(OpenGenericType, Token), UnitSequenceMatchingWeight.WildcardMatchingUnit - 1); UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(childMatcher) .AddBuildAction(BuildStage.Create, CreateByReflectionBuildAction.Instance); return(new Tuner(childMatcher)); }
/// <summary> /// Used to make a build plan for a unit only if it is building in a context of building <paramref name="type" /> with token <paramref name="token" /> /// </summary> public SequenceTuner Building([NotNull] Type type, object token = null) { if (type == null) { throw new ArgumentNullException(nameof(type)); } var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type(type, token)); return(new SequenceTuner(UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(unitSequenceMatcher))); }
/// <summary> /// Provided values will be injected into properties of the created object. See <see cref="ForProperty" /> for details. /// Also value can be a build plan returned by one of the method of the <see cref="Property" /> class, which specifies properties to inject dependencies. /// </summary> public Tuner InjectProperty(params object[] values) { UnitSequenceMatcher.AddBuildAction(BuildStage.Initialize, InjectIntoPropertiesBuildAction.Instance); foreach (var value in values) { if (value is IPropertyValueBuildPlan buildPlan) { buildPlan.Apply(UnitSequenceMatcher); } else if (value is IBuildPlan) { throw new ArmatureException("IPropertyValueBuildPlan or plain object value expected"); } else { UnitSequenceMatcher .AddOrGetUnitSequenceMatcher(new LastUnitSequenceMatcher(new PropertyByValueMatcher(value), InjectPointMatchingWeight.WeakTypedParameter)) .AddBuildAction(BuildStage.Create, new SingletonBuildAction(value)); } } return(this); }
/// <summary> /// Used to add some details to build plan of any building unit in context of currently building one /// </summary> public Tuner TreatAll() { var unitSequenceMatcher = new AnyUnitSequenceMatcher(); return(new Tuner(UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(unitSequenceMatcher))); }
/// <summary> /// Used to make a build plan for <typeparamref name="T" />. /// How <typeparamref name="T" /> should be treated is specified by subsequence calls using returned object /// </summary> public TreatingTuner <T> Treat <T>(object token = null) { var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type <T>(token)); return(new TreatingTuner <T>(UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(unitSequenceMatcher))); }
/// <summary> /// Used to make a build plan for Unit of type <paramref name="type"/>. /// How it should be treated is specified by subsequence calls using returned object. /// </summary> public TreatingTuner Treat([NotNull] Type type, object token = null) { var unitSequenceMatcher = new WildcardUnitSequenceMatcher(Match.Type(type, token)); return(new TreatingTuner(UnitSequenceMatcher.AddOrGetUnitSequenceMatcher(unitSequenceMatcher))); }