Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
 /// <summary>
 ///   Register Unit as an eternal singleton <see cref="SingletonBuildAction" /> for details
 /// </summary>
 public void AsSingleton() => UnitSequenceMatcher.AddBuildAction(BuildStage.Cache, new SingletonBuildAction());
Exemplo n.º 3
0
 public Tuner AsIs()
 {
     UnitSequenceMatcher.AddBuildAction(BuildStage.Create, Default.CreationBuildAction);
     return(new Tuner(UnitSequenceMatcher));
 }
Exemplo n.º 4
0
 /// <summary>
 ///   When generic type belonging to class described by open generic type passed to <see cref="BuildPlansCollectionExtension.TreatOpenGeneric"/>
 ///   is requested to inject, object of generic type <paramref name="openGenericType"/> injected. Tune how it is created by subsequence tuner calls.
 /// </summary>
 public OpenGenericCreationTuner As(Type openGenericType, object token = null)
 {
     UnitSequenceMatcher.AddBuildAction(BuildStage.Create, new RedirectOpenGenericTypeBuildAction(openGenericType, token));
     return(new OpenGenericCreationTuner(UnitSequenceMatcher, openGenericType, token));
 }