34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using DD.Persistence.Client.Clients.Mapping.Abstractions;
|
|
using DD.Persistence.Models.Configurations;
|
|
using Microsoft.Extensions.Logging;
|
|
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;
|
|
private readonly ILogger<TimestampedSetMapper> logger;
|
|
|
|
public MapperStorage(MappingConfig mappingConfigs, ILogger<TimestampedSetMapper> logger)
|
|
{
|
|
this.mappingConfigs = mappingConfigs;
|
|
this.logger = logger;
|
|
}
|
|
|
|
|
|
public TimestampedSetMapper? GetMapper(Guid idDiscriminator)
|
|
{
|
|
if (mappingConfigs.TryGetValue(idDiscriminator, out var type))
|
|
return mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper(idDiscriminator, type, logger));
|
|
|
|
return null;
|
|
}
|
|
|
|
public TimestampedSetMapper GetMapper<T>(Guid idDiscriminator)
|
|
{
|
|
return mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper(idDiscriminator, typeof(T), logger));
|
|
}
|
|
}
|