30 lines
997 B
C#
30 lines
997 B
C#
using DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
using DD.Persistence.Models.Configurations;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace DD.Persistence.Client.Clients.Mapping;
|
|
internal class MapperStorage : IMapperStorage
|
|
{
|
|
private readonly ConcurrentDictionary<Guid, TimestampedSetMapper> mapperCache = new();
|
|
private readonly MappingConfig mappingConfigs;
|
|
public MapperStorage(MappingConfig mappingConfigs)
|
|
{
|
|
this.mappingConfigs = mappingConfigs;
|
|
}
|
|
|
|
|
|
public TimestampedSetMapper? GetMapper(Guid idDiscriminator)
|
|
{
|
|
if(mappingConfigs.TryGetValue(idDiscriminator, out var type))
|
|
return mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper(idDiscriminator, type));
|
|
|
|
return null;
|
|
}
|
|
|
|
public TimestampedSetMapper GetMapper<T>(Guid idDiscriminator)
|
|
{
|
|
return mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper(idDiscriminator, typeof(T)));
|
|
}
|
|
}
|