2026-10-01 11:01:08 +02:00
|
|
|
using MongoDB.Entities;
|
|
|
|
|
|
|
|
|
|
namespace PrivaPub.Infrastructure.Data
|
|
|
|
|
{
|
|
|
|
|
public static class EntityMaps
|
|
|
|
|
{
|
2026-10-07 11:40:06 +02:00
|
|
|
static readonly Lock Gate = new();
|
|
|
|
|
static bool _warm;
|
|
|
|
|
|
|
|
|
|
// once per process, one map at a time: test hosts boot side by side
|
2026-10-01 11:01:08 +02:00
|
|
|
public static void Warm()
|
2026-10-07 11:40:06 +02:00
|
|
|
{
|
|
|
|
|
lock (Gate)
|
|
|
|
|
{
|
|
|
|
|
if (_warm)
|
|
|
|
|
return;
|
|
|
|
|
Map();
|
|
|
|
|
_warm = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void Map()
|
2026-10-01 11:01:08 +02:00
|
|
|
{
|
|
|
|
|
var collection = typeof(DB).GetMethods()
|
|
|
|
|
.Single(m => m.Name == nameof(DB.Collection) && m.IsGenericMethodDefinition && m.GetParameters().Length == 0);
|
|
|
|
|
var entities = typeof(EntityMaps).Assembly.GetTypes()
|
|
|
|
|
.Where(t => t is { IsClass: true, IsAbstract: false, IsGenericTypeDefinition: false } && typeof(IEntity).IsAssignableFrom(t))
|
|
|
|
|
.OrderBy(t => t.FullName, StringComparer.Ordinal);
|
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
collection.MakeGenericMethod(entity).Invoke(DB.Default, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|