CodeLiturgy.Dashboard/BlueWest.Api/Context/Interfaces/ExchangeInterface.cs

63 lines
1.8 KiB
C#
Raw Normal View History

2022-08-19 19:47:35 +03:00
using System;
using System.Threading.Tasks;
using BlueWest.Tools;
using BlueWest.WebApi.MySQL;
namespace BlueWest.WebApi.Interfaces
{
public struct ExchangeEvent { }
public class ExchangeInterface : EventListener<ExchangeEvent>, 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<ExchangeEvent>(this);
_eventManager.TriggerEvent<ExchangeEvent>(new ExchangeEvent());
Console.WriteLine($"{nameof(ExchangeInterface)} Just started!");
}
public void OnEvent(ExchangeEvent eventType)
{
Console.WriteLine($"Service received exchange {nameof(ExchangeEvent)}");
}
/// <summary>
/// Stop Listening for events
/// </summary>
public void Dispose()
{
_eventManager.EventStopListening<ExchangeEvent>(this);
}
public ValueTask DisposeAsync()
{
_eventManager.EventStopListening<ExchangeEvent>(this);
return ValueTask.CompletedTask;
}
}
}