-
Notifications
You must be signed in to change notification settings - Fork 50
/
ExchangeSubscriptionsCacheFactory.cs
50 lines (42 loc) · 1.55 KB
/
ExchangeSubscriptionsCacheFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using DevelopmentInProgress.TradeView.Core.Interfaces;
using DevelopmentInProgress.TradeView.Core.Enums;
using System;
using System.Collections.Concurrent;
namespace DevelopmentInProgress.TradeServer.StrategyExecution.WebHost.Cache.Subscriptions
{
public class ExchangeSubscriptionsCacheFactory : IExchangeSubscriptionsCacheFactory
{
private readonly IExchangeService exchangeService;
private readonly ConcurrentDictionary<Exchange, IExchangeSubscriptionsCache> exchangeSubscriptionsCache;
private bool disposed;
public ExchangeSubscriptionsCacheFactory(IExchangeService exchangeService)
{
this.exchangeService = exchangeService;
exchangeSubscriptionsCache = new ConcurrentDictionary<Exchange, IExchangeSubscriptionsCache>();
}
public IExchangeSubscriptionsCache GetExchangeSubscriptionsCache(Exchange exchange)
{
return exchangeSubscriptionsCache.GetOrAdd(exchange, new ExchangeSubscriptionsCache(exchange, exchangeService));
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
{
return;
}
if (disposing)
{
foreach(var subscriptionsCache in exchangeSubscriptionsCache.Values)
{
subscriptionsCache.Dispose();
}
}
disposed = true;
}
}
}