#45: add first implementation of IMultipleMultitonRegistration

pull/47/head
Simon G 5 years ago
parent 699a852506
commit b324ee74fd
  1. 11
      LightweightIocContainer/Interfaces/Registrations/IMultipleMultitonRegistration.cs
  2. 38
      LightweightIocContainer/Registrations/MultipleMultitonRegistration.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<TInterface1, TInterface2, TImplementation> : IMultitonRegistration<TInterface1, TImplementation>, IMultipleRegistration<TInterface1, TInterface2, TImplementation> where TImplementation : TInterface1, TInterface2
{
}
}

@ -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<TInterface1, TInterface2, TImplementation> : MultitonRegistration<TInterface1, TImplementation>, IMultipleMultitonRegistration<TInterface1, TInterface2, TImplementation> where TImplementation : TInterface1, TInterface2
{
public MultipleMultitonRegistration(Type interfaceType1, Type interfaceType2, Type implementationType, Type scope)
: base(interfaceType1, implementationType, scope)
{
Registrations = new List<IRegistration>()
{
new MultitonRegistration<TInterface1, TImplementation>(interfaceType1, implementationType, scope),
new MultitonRegistration<TInterface2, TImplementation>(interfaceType2, implementationType, scope)
};
}
public List<IRegistration> Registrations { get; }
public override ITypedRegistrationBase<TInterface1, TImplementation> OnCreate(Action<TImplementation> action)
{
foreach (var registration in Registrations)
{
if (registration is IMultitonRegistration<TInterface2, TImplementation> interface2Registration)
interface2Registration.OnCreate(action);
else if (registration is IMultitonRegistration<TInterface1, TImplementation> interface1Registration)
interface1Registration.OnCreate(action);
}
return this;
}
}
}
Loading…
Cancel
Save