LootDumpProcessor/Storage/DataStorageFactory.cs
chomp 6e4c7abf73 dump-processor-cleanup (#6)
Co-authored-by: Alex <alex@dm-me-for-questions.com>
Reviewed-on: SPT-AKI/LootDumpProcessor#6
2024-04-16 18:29:40 +00:00

40 lines
1.2 KiB
C#

using LootDumpProcessor.Storage.Implementations.File;
using LootDumpProcessor.Storage.Implementations.Memory;
namespace LootDumpProcessor.Storage;
public static class DataStorageFactory
{
private static readonly Dictionary<DataStorageTypes, IDataStorage> _dataStorage = new();
private static object lockObject = new();
/**
* Requires LootDumpProcessorContext to be initialized before using
*/
public static IDataStorage GetInstance()
{
return GetInstance(LootDumpProcessorContext.GetConfig().DataStorageConfig.DataStorageType);
}
public static IDataStorage GetInstance(DataStorageTypes type)
{
IDataStorage dataStorage;
lock (lockObject)
{
if (!_dataStorage.TryGetValue(type, out dataStorage))
{
dataStorage = type switch
{
DataStorageTypes.File => new FileDataStorage(),
DataStorageTypes.Memory => new MemoryDataStorage(),
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
_dataStorage.Add(type, dataStorage);
}
}
return dataStorage;
}
}