LootDumpProcessor/Storage/DataStorageFactory.cs

40 lines
1.2 KiB
C#
Raw Normal View History

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 Dictionary<DataStorageTypes, IDataStorage> _dataStorage = new();
2023-08-12 19:08:38 +01:00
private static object lockObject = new();
2023-08-12 19:08:38 +01:00
/**
* 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
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.Add(type, dataStorage);
}
}
return dataStorage;
}
}