diff --git a/LightweightIocContainer/Interfaces/Registrations/IMultipleMultitonRegistration.cs b/LightweightIocContainer/Interfaces/Registrations/IMultipleMultitonRegistration.cs new file mode 100644 index 0000000..cfc9c7f --- /dev/null +++ b/LightweightIocContainer/Interfaces/Registrations/IMultipleMultitonRegistration.cs @@ -0,0 +1,11 @@ +// Author: Gockner, Simon +// Created: 2020-11-19 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +namespace LightweightIocContainer.Interfaces.Registrations +{ + public interface IMultipleMultitonRegistration : IMultitonRegistration, IMultipleRegistration where TImplementation : TInterface1, TInterface2 + { + + } +} \ No newline at end of file diff --git a/LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs b/LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs new file mode 100644 index 0000000..abc784f --- /dev/null +++ b/LightweightIocContainer/Registrations/MultipleMultitonRegistration.cs @@ -0,0 +1,38 @@ +// Author: Gockner, Simon +// Created: 2020-11-19 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System; +using System.Collections.Generic; +using LightweightIocContainer.Interfaces.Registrations; + +namespace LightweightIocContainer.Registrations +{ + public class MultipleMultitonRegistration : MultitonRegistration, IMultipleMultitonRegistration where TImplementation : TInterface1, TInterface2 + { + public MultipleMultitonRegistration(Type interfaceType1, Type interfaceType2, Type implementationType, Type scope) + : base(interfaceType1, implementationType, scope) + { + Registrations = new List() + { + new MultitonRegistration(interfaceType1, implementationType, scope), + new MultitonRegistration(interfaceType2, implementationType, scope) + }; + } + + public List Registrations { get; } + + public override ITypedRegistrationBase OnCreate(Action action) + { + foreach (var registration in Registrations) + { + if (registration is IMultitonRegistration interface2Registration) + interface2Registration.OnCreate(action); + else if (registration is IMultitonRegistration interface1Registration) + interface1Registration.OnCreate(action); + } + + return this; + } + } +} \ No newline at end of file