From ee7164cf95eb00b2de487f375eec6467ad46fe44 Mon Sep 17 00:00:00 2001 From: "Simon G." Date: Tue, 4 Nov 2025 14:34:01 +0100 Subject: [PATCH] #61: set dispose strategy and parameters for each child registration --- .../LightweightIocContainer.xml | 25 +++++++++++ .../Registrations/MultipleRegistration.cs | 45 +++++++++++++++++++ .../Registrations/RegistrationBase.cs | 2 +- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/LightweightIocContainer/LightweightIocContainer.xml b/LightweightIocContainer/LightweightIocContainer.xml index af776ea..ab26ed9 100644 --- a/LightweightIocContainer/LightweightIocContainer.xml +++ b/LightweightIocContainer/LightweightIocContainer.xml @@ -1344,6 +1344,31 @@ A of s that are registered within this + + + Pass parameters that will be used to an instance of this + Parameters set with this method are always inserted at the beginning of the argument list if more parameters are given when resolving + + The parameters + The current instance of this + are already set or no parameters given + + + + Pass parameters that will be used to an instance of this + Parameters set with this method are inserted at the position in the argument list that is passed with the parameter if more parameters are given when resolving + + The parameters with their position + The current instance of this + are already set or no parameters given + + + + Add a for the + + The + The current instance of this + An to register multiple interfaces for on implementation type diff --git a/LightweightIocContainer/Registrations/MultipleRegistration.cs b/LightweightIocContainer/Registrations/MultipleRegistration.cs index d5732a7..0de4f2a 100644 --- a/LightweightIocContainer/Registrations/MultipleRegistration.cs +++ b/LightweightIocContainer/Registrations/MultipleRegistration.cs @@ -2,8 +2,10 @@ // Created: 2019-12-07 // Copyright(c) 2019 SimonG. All Rights Reserved. +using LightweightIocContainer.Exceptions; using LightweightIocContainer.Interfaces; using LightweightIocContainer.Interfaces.Registrations; +using LightweightIocContainer.Interfaces.Registrations.Fluent; namespace LightweightIocContainer.Registrations; @@ -31,6 +33,49 @@ internal abstract class MultipleRegistration : Typ /// A of s that are registered within this /// public List Registrations { get; protected init; } = []; + + /// + /// Pass parameters that will be used to an instance of this + /// Parameters set with this method are always inserted at the beginning of the argument list if more parameters are given when resolving + /// + /// The parameters + /// The current instance of this + /// are already set or no parameters given + public override IRegistrationBase WithParameters(params object[] parameters) + { + foreach (IWithParameters registration in Registrations.OfType()) + registration.WithParameters(parameters); + + return this; + } + + /// + /// Pass parameters that will be used to an instance of this + /// Parameters set with this method are inserted at the position in the argument list that is passed with the parameter if more parameters are given when resolving + /// + /// The parameters with their position + /// The current instance of this + /// are already set or no parameters given + public override IRegistrationBase WithParameters(params (int index, object parameter)[] parameters) + { + foreach (IWithParameters registration in Registrations.OfType()) + registration.WithParameters(parameters); + + return this; + } + + /// + /// Add a for the + /// + /// The + /// The current instance of this + public override IRegistrationBase WithDisposeStrategy(DisposeStrategy disposeStrategy) + { + foreach (IWithDisposeStrategy registration in Registrations.OfType()) + registration.WithDisposeStrategy(disposeStrategy); + + return this; + } } /// diff --git a/LightweightIocContainer/Registrations/RegistrationBase.cs b/LightweightIocContainer/Registrations/RegistrationBase.cs index e131689..f9c08a3 100644 --- a/LightweightIocContainer/Registrations/RegistrationBase.cs +++ b/LightweightIocContainer/Registrations/RegistrationBase.cs @@ -140,7 +140,7 @@ internal abstract class RegistrationBase : IRegistrationBase, IWithFactoryIntern /// /// The /// The current instance of this - public IRegistrationBase WithDisposeStrategy(DisposeStrategy disposeStrategy) + public virtual IRegistrationBase WithDisposeStrategy(DisposeStrategy disposeStrategy) { DisposeStrategy = disposeStrategy; return this;