mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-11 01:46:12 +00:00
wip
This commit is contained in:
parent
acd9b0d533
commit
8a869e8e1d
44
CryptoExchange.Net/Clients/CryptoExchangeClient.cs
Normal file
44
CryptoExchange.Net/Clients/CryptoExchangeClient.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Interfaces.CommonClients;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.Clients
|
||||
{
|
||||
public class CryptoExchangeClient : ICryptoExchangeClient, IDisposable
|
||||
{
|
||||
private Dictionary<Type, object?> _serviceCache = new Dictionary<Type, object?>();
|
||||
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public CryptoExchangeClient(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_serviceCache = new Dictionary<Type, object?>();
|
||||
}
|
||||
|
||||
public IEnumerable<ISpotClient> GetSpotClients()
|
||||
{
|
||||
return _serviceProvider.GetServices<ISpotClient>().ToList();
|
||||
}
|
||||
|
||||
public T? TryGet<T>()
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (_serviceCache.TryGetValue(type, out var value))
|
||||
return (T?)value;
|
||||
|
||||
var result = _serviceProvider.GetService<T>();
|
||||
_serviceCache.Add(type, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_serviceCache.Clear();
|
||||
}
|
||||
}
|
||||
}
|
15
CryptoExchange.Net/Interfaces/ICryptoExchangeClient.cs
Normal file
15
CryptoExchange.Net/Interfaces/ICryptoExchangeClient.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Interfaces.CommonClients;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.Clients
|
||||
{
|
||||
public interface ICryptoExchangeClient
|
||||
{
|
||||
IEnumerable<ISpotClient> GetSpotClients();
|
||||
T? TryGet<T>();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user