/// <summary> /// Initializes a new instance of the <see cref="BoundConstructor"/> class, for an unsuccessful bind. /// </summary> /// <param name="binder">The binder that generated this binding.</param> /// <param name="firstNonBindableParameter">The first parameter that prevented binding.</param> internal BoundConstructor(ConstructorBinder binder, ParameterInfo firstNonBindableParameter) { Binder = binder; CanInstantiate = false; _firstNonBindableParameter = firstNonBindableParameter ?? throw new ArgumentNullException(nameof(firstNonBindableParameter)); _factory = null; _valueRetrievers = null; }
/// <summary> /// Initializes a new instance of the <see cref="BoundConstructor"/> class for a successful bind. /// </summary> /// <param name="binder">The binder that generated this binding.</param> /// <param name="factory">The instance factory.</param> /// <param name="valueRetrievers">The set of value-retrieval functions.</param> internal BoundConstructor(ConstructorBinder binder, Func <object?[], object> factory, Func <object?>[] valueRetrievers) { CanInstantiate = true; Binder = binder; _factory = factory ?? throw new ArgumentNullException(nameof(factory)); _valueRetrievers = valueRetrievers ?? throw new ArgumentNullException(nameof(valueRetrievers)); _firstNonBindableParameter = null; }
/// <inheritdoc/> public void ConfigurePipeline(IComponentRegistryServices componentRegistryServices, IResolvePipelineBuilder pipelineBuilder) { if (componentRegistryServices is null) { throw new ArgumentNullException(nameof(componentRegistryServices)); } if (pipelineBuilder is null) { throw new ArgumentNullException(nameof(pipelineBuilder)); } // Locate the possible constructors at container build time. var availableConstructors = ConstructorFinder.FindConstructors(_implementationType); if (availableConstructors.Length == 0) { throw new NoConstructorsFoundException(_implementationType, string.Format(CultureInfo.CurrentCulture, ReflectionActivatorResources.NoConstructorsAvailable, _implementationType, ConstructorFinder)); } var binders = new ConstructorBinder[availableConstructors.Length]; for (var idx = 0; idx < availableConstructors.Length; idx++) { binders[idx] = new ConstructorBinder(availableConstructors[idx]); } _constructorBinders = binders; pipelineBuilder.Use(ToString(), PipelinePhase.Activation, MiddlewareInsertionMode.EndOfPhase, (ctxt, next) => { ctxt.Instance = ActivateInstance(ctxt, ctxt.Parameters); next(ctxt); }); }
/// <summary> /// Initializes a new instance of the <see cref="BoundConstructor"/> class, for an unsuccessful bind. /// </summary> /// <param name="binder">The binder that generated this binding.</param> /// <param name="firstNonBindableParameter">The first parameter that prevented binding.</param> public static BoundConstructor ForBindFailure(ConstructorBinder binder, ParameterInfo firstNonBindableParameter) => new BoundConstructor(binder, firstNonBindableParameter);
public static BoundConstructor ForBindSuccess(ConstructorBinder binder, Func <object?[], object> factory, Func <object?>[] valueRetrievers) => new BoundConstructor(binder, factory, valueRetrievers);