0
0
mirror of https://github.com/sp-tarkov/loot-dump-processor.git synced 2025-02-13 09:50:44 -05:00

32 lines
1.0 KiB
C#
Raw Normal View History

using System.Collections.Concurrent;
using LootDumpProcessor.Storage.Implementations.File;
2023-08-12 19:08:38 +01:00
using LootDumpProcessor.Storage.Implementations.Memory;
namespace LootDumpProcessor.Storage;
public static class DataStorageFactory
{
private static readonly ConcurrentDictionary<DataStorageTypes, IDataStorage> DataStorage = new();
2023-08-12 19:08:38 +01:00
/**
* Requires LootDumpProcessorContext to be initialized before using
*/
public static IDataStorage GetInstance() =>
GetInstance(LootDumpProcessorContext.GetConfig().DataStorageConfig.DataStorageType);
2023-08-12 19:08:38 +01:00
private static IDataStorage GetInstance(DataStorageTypes type)
2023-08-12 19:08:38 +01:00
{
if (DataStorage.TryGetValue(type, out var dataStorage)) return dataStorage;
dataStorage = type switch
2023-08-12 19:08:38 +01:00
{
DataStorageTypes.File => new FileDataStorage(),
DataStorageTypes.Memory => new MemoryDataStorage(),
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
2023-08-12 19:08:38 +01:00
DataStorage.TryAdd(type, dataStorage);
2023-08-12 19:08:38 +01:00
return dataStorage;
}
}