0
0
mirror of https://github.com/sp-tarkov/loot-dump-processor.git synced 2025-02-13 09:50:44 -05:00
bluextx 465ad95cb5 Refactored code to use System.Text.Json and improved code style
The changes include:
- Replaced Newtonsoft.Json with System.Text.Json for serialization
- Removed redundant JsonProperty attributes and simplified model classes
- Converted static fields to constants where appropriate
- Improved code formatting and readability
- Simplified method bodies and expressions
- Removed unused imports and cleaned up namespaces
2025-01-11 10:52:23 +03:00

38 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() =>
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;
}
}