using System; using System.Threading.Tasks; using BlueWest.Tools; using BlueWest.WebApi.MySQL; namespace BlueWest.WebApi.Interfaces { public struct ExchangeEvent { } public class ExchangeInterface : EventListener, IDisposable, IAsyncDisposable { private readonly EventManager _eventManager; private readonly CountryDbContext _countryDbContext; private readonly FinanceDbContext _financeDbContext; private readonly UserDbContext _userDbContext; public ExchangeInterface( CountryDbContext countryDbContext, FinanceDbContext financeDbContext, UserDbContext userDbContext, EventManager eventManager) { _countryDbContext = countryDbContext; _financeDbContext = financeDbContext; _userDbContext = userDbContext; _eventManager = eventManager; Init(); } public ExchangeInterface() { } private void Init() { _eventManager.EventStartListening(this); _eventManager.TriggerEvent(new ExchangeEvent()); Console.WriteLine($"{nameof(ExchangeInterface)} Just started!"); } public void OnEvent(ExchangeEvent eventType) { Console.WriteLine($"Service received exchange {nameof(ExchangeEvent)}"); } /// /// Stop Listening for events /// public void Dispose() { _eventManager.EventStopListening(this); } public ValueTask DisposeAsync() { _eventManager.EventStopListening(this); return ValueTask.CompletedTask; } } }