LootDumpProcessor/Process/Reader/Intake/IntakeReaderFactory.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

28 lines
1.0 KiB
C#

namespace LootDumpProcessor.Process.Reader.Intake;
public static class IntakeReaderFactory
{
private static readonly Dictionary<IntakeReaderTypes, IIntakeReader> Instances = new();
private static readonly object DictionaryLock = new();
public static IIntakeReader GetInstance()
{
var type = LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig?.IntakeReaderType ??
IntakeReaderTypes.Json;
lock (DictionaryLock)
{
if (!Instances.TryGetValue(type, out var intakeReader))
{
intakeReader = type switch
{
IntakeReaderTypes.Json => new JsonFileIntakeReader(),
_ => throw new ArgumentOutOfRangeException(
"IntakeReaderType",
"Value was not defined on IntakeReaderConfig"
)
};
Instances.Add(type, intakeReader);
}
return intakeReader;
}
}
}