using System;
using System.Threading.Tasks;
using BlueWest.Domain;
using BlueWest.Domain;
using BlueWest.Tools;
using BlueWest.WebApi.Context;
namespace BlueWest.WebApi.Interfaces
{
///
/// Empty constructor
///
public struct ExchangeEvent { }
///
/// Interface for getting and storing exchange rates data
///
///
public sealed class ExchangeInterface : EventListener, IDisposable, IAsyncDisposable
{
private readonly ApplicationUserDbContext _applicationUserDbContext;
private readonly EventManager _eventManager;
private readonly CountryDbContext _countryDbContext;
private readonly FinanceDbContext _financeDbContext;
private readonly UserDbContext _userDbContext;
#region Initialization
///
/// Database Ef context constructor
///
/// Country context
/// Finance context
/// User context
/// Event manager injection
public ExchangeInterface(
ApplicationUserDbContext applicationUserDbContext,
CountryDbContext countryDbContext,
FinanceDbContext financeDbContext,
UserDbContext userDbContext,
EventManager eventManager)
{
_applicationUserDbContext = applicationUserDbContext;
_countryDbContext = countryDbContext;
_financeDbContext = financeDbContext;
_userDbContext = userDbContext;
_eventManager = eventManager;
Init();
}
///
/// Database Ef context constructor
///
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 on dispose
///
public void Dispose()
{
_eventManager.EventStopListening(this);
}
///
/// Stop Listening for events on dispose async
///
///
public ValueTask DisposeAsync()
{
_eventManager.EventStopListening(this);
return ValueTask.CompletedTask;
}
}
}