diff --git a/LightweightIocContainer/Interfaces/Registrations/IMultipleRegistration.cs b/LightweightIocContainer/Interfaces/Registrations/IMultipleRegistration.cs new file mode 100644 index 0000000..99c4b0c --- /dev/null +++ b/LightweightIocContainer/Interfaces/Registrations/IMultipleRegistration.cs @@ -0,0 +1,22 @@ +// Author: Simon Gockner +// Created: 2019-12-07 +// Copyright(c) 2019 SimonG. All Rights Reserved. + +using System.Collections.Generic; +using LightweightIocContainer.Interfaces.Registrations.FluentProviders; + +namespace LightweightIocContainer.Interfaces.Registrations +{ + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + public interface IMultipleRegistration : ITypedRegistrationBase, IOnCreate + { + /// + /// A of s that are registered within this + /// + List Registrations { get; } + } +} \ No newline at end of file diff --git a/LightweightIocContainer/Registrations/MultipleRegistration.cs b/LightweightIocContainer/Registrations/MultipleRegistration.cs new file mode 100644 index 0000000..bebb459 --- /dev/null +++ b/LightweightIocContainer/Registrations/MultipleRegistration.cs @@ -0,0 +1,59 @@ +// Author: Simon Gockner +// Created: 2019-12-07 +// Copyright(c) 2019 SimonG. All Rights Reserved. + +using System; +using System.Collections.Generic; +using LightweightIocContainer.Interfaces.Registrations; + +namespace LightweightIocContainer.Registrations +{ + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + public class MultipleRegistration : TypedRegistrationBase, IMultipleRegistration + { + /// + /// An to register multiple interfaces for on implementation type + /// + /// The of the first interface + /// The of the second interface + /// The of the implementation + /// The of this + public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type implementationType, Lifestyle lifestyle) + : base(interfaceType1, implementationType, lifestyle) + { + Registrations = new List() + { + new DefaultRegistration(interfaceType1, implementationType, lifestyle), + new DefaultRegistration(interfaceType2, implementationType, lifestyle) + }; + } + + /// + /// A of s that are registered within this + /// + public List Registrations { get; } + + /// + /// Pass an for each interface that will be invoked when instances of the types are created + /// + /// The first + /// The second + /// The current instance of this + public IMultipleRegistration OnCreate(Action action1, Action action2) + { + foreach (var registration in Registrations) + { + if (registration is IDefaultRegistration interface2Registration) + interface2Registration.OnCreate(action2); + else if (registration is IDefaultRegistration interface1Registration) + interface1Registration.OnCreate(action1); + } + + return this; + } + } +} \ No newline at end of file