using System; using System.Collections.Generic; namespace Svelto.ServiceLayer.Experimental { public abstract class ServiceEventContainer : IServiceEventContainer { public void Dispose() { foreach (var listener in _listeners) { listener.Dispose(); } _listeners.Clear(); } protected ServiceEventContainer() { //call all the AddRelation in the implementation if you wish } public void ListenTo(TDelegate callBack) where TListener : class, IServiceEventListener where TDelegate : Delegate { var concreteType = _registeredTypes[typeof(TListener)]; var listener = (TListener)Activator.CreateInstance(concreteType); listener.SetCallback(callBack); _listeners.Add(listener); } protected void AddRelation() where TInterface : IServiceEventListenerBase where TConcrete : TInterface { _registeredTypes.Add(typeof(TInterface), typeof(TConcrete)); } readonly List _listeners = new List(); readonly Dictionary _registeredTypes = new Dictionary(); } }