chomp
6e4c7abf73
Co-authored-by: Alex <alex@dm-me-for-questions.com> Reviewed-on: SPT-AKI/LootDumpProcessor#6
40 lines
1.2 KiB
C#
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;
|
|
}
|
|
} |