diff --git a/SqlData/Persistence/Common/ConfigurationResolver.cs b/SqlData/Persistence/Common/ConfigurationResolver.cs new file mode 100644 index 0000000..907b8ca --- /dev/null +++ b/SqlData/Persistence/Common/ConfigurationResolver.cs @@ -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(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}."); + } +} \ No newline at end of file