feat: add resolver for getting configuration Type

This commit is contained in:
Polianin Nikita 2024-05-30 20:14:46 +03:00
parent 4c93ed282d
commit 348b78b84e

View File

@ -0,0 +1,23 @@
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations;
using System;
using System.Linq;
using System.Reflection;
namespace Mirea.Api.DataAccess.Persistence.Common;
public static class ConfigurationResolver
{
public static Type GetConfigurationType<TEntity>(DatabaseProvider provider)
where TEntity : class
{
var entityType = typeof(TEntity);
var providerNamespace = typeof(Mark).Namespace + "." + Enum.GetName(provider);
var assembly = Assembly.GetExecutingAssembly();
var configurationType = assembly.GetTypes()
.FirstOrDefault(t => t.Namespace != null && t.Namespace.StartsWith(providerNamespace) && t.Name == $"{entityType.Name}Configuration");
return configurationType ??
throw new InvalidOperationException($"Configuration type not found for entity {entityType.Name} and provider {provider}.");
}
}