From b48ef586ac22682cfe68f26311500b02c2846a0f Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 6 Jan 2026 23:23:57 -0500 Subject: [PATCH] feat(ExcelIO): add ExcelMapRegistry for DI integration --- .../Mapping/ExcelMapRegistry.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 NEW/src/JdeScoping.ExcelIO/Mapping/ExcelMapRegistry.cs diff --git a/NEW/src/JdeScoping.ExcelIO/Mapping/ExcelMapRegistry.cs b/NEW/src/JdeScoping.ExcelIO/Mapping/ExcelMapRegistry.cs new file mode 100644 index 0000000..c5e96b8 --- /dev/null +++ b/NEW/src/JdeScoping.ExcelIO/Mapping/ExcelMapRegistry.cs @@ -0,0 +1,45 @@ +namespace JdeScoping.ExcelIO.Mapping; + +/// +/// Registry for Excel class maps, used for DI and lookup. +/// +public sealed class ExcelMapRegistry +{ + private readonly Dictionary _maps = new(); + + /// + /// Registers a map for a type. + /// + public void Register(ExcelClassMap map) + { + _maps[typeof(T)] = map; + } + + /// + /// Gets the map for a type. + /// + public IExcelClassMap GetMap() => GetMap(typeof(T)); + + /// + /// Gets the map for a type. + /// + public IExcelClassMap GetMap(Type type) + { + if (_maps.TryGetValue(type, out var map)) + return map; + + throw new InvalidOperationException( + $"No Excel map registered for type {type.Name}. " + + $"Register a map using ExcelMapRegistry.Register()."); + } + + /// + /// Checks if a map exists for a type. + /// + public bool HasMap() => HasMap(typeof(T)); + + /// + /// Checks if a map exists for a type. + /// + public bool HasMap(Type type) => _maps.ContainsKey(type); +}