using System; using System.Threading.Tasks; using BlueWest.Tools; using BlueWest.WebApi.MySQL; namespace BlueWest.WebApi.Interfaces { public struct ExchangeEvent { } /// /// Interface for getting and storing exchange rates data /// /// public sealed class ExchangeInterface : EventListener, IDisposable, IAsyncDisposable { private readonly EventManager _eventManager; private readonly CountryDbContext _countryDbContext; private readonly FinanceDbContext _financeDbContext; private readonly UserDbContext _userDbContext; #region Initialization 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); Console.WriteLine($"{nameof(ExchangeInterface)} Just started!"); } #endregion /// /// On Exchange Event /// /// 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; } } }