37 lines
1003 B
C#
37 lines
1003 B
C#
using BeWo.Data.Entities;
|
|
using BeWo.Service.AI.Mappings;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BeWo.Service.AI.Core
|
|
{
|
|
internal class AiMapperFactory
|
|
{
|
|
private readonly Dictionary<Type, object> _Mappers;
|
|
|
|
public AiMapperFactory()
|
|
{
|
|
_Mappers = new Dictionary<Type, object>()
|
|
{
|
|
{typeof(CompactCustomerAiMapping), new Lazy<CompactCustomerAiMapping>(() => new CompactCustomerAiMapping()) },
|
|
{typeof(CustomerAiMapping), new Lazy<CustomerAiMapping>(() => new CustomerAiMapping()) },
|
|
{typeof(ServiceRecordAiMapping), new Lazy<ServiceRecordAiMapping>(() => new ServiceRecordAiMapping()) },
|
|
};
|
|
}
|
|
|
|
public T GetMapper<T>() where T : class
|
|
{
|
|
if (_Mappers.TryGetValue(typeof(T), out var lazy))
|
|
{
|
|
return (lazy as Lazy<T>)?.Value;
|
|
}
|
|
|
|
throw new InvalidOperationException($"No mapper registered for type {typeof(T).Name}");
|
|
}
|
|
}
|
|
}
|