feat(ExcelIO): add ExcelMapRegistry for DI integration

This commit is contained in:
Joseph Doherty
2026-01-06 23:23:57 -05:00
parent 45243aa3ca
commit b48ef586ac
@@ -0,0 +1,45 @@
namespace JdeScoping.ExcelIO.Mapping;
/// <summary>
/// Registry for Excel class maps, used for DI and lookup.
/// </summary>
public sealed class ExcelMapRegistry
{
private readonly Dictionary<Type, IExcelClassMap> _maps = new();
/// <summary>
/// Registers a map for a type.
/// </summary>
public void Register<T>(ExcelClassMap<T> map)
{
_maps[typeof(T)] = map;
}
/// <summary>
/// Gets the map for a type.
/// </summary>
public IExcelClassMap GetMap<T>() => GetMap(typeof(T));
/// <summary>
/// Gets the map for a type.
/// </summary>
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().");
}
/// <summary>
/// Checks if a map exists for a type.
/// </summary>
public bool HasMap<T>() => HasMap(typeof(T));
/// <summary>
/// Checks if a map exists for a type.
/// </summary>
public bool HasMap(Type type) => _maps.ContainsKey(type);
}