Use the configuration depending on the selected database provider #13
23
SqlData/Persistence/Common/ConfigurationResolver.cs
Normal file
23
SqlData/Persistence/Common/ConfigurationResolver.cs
Normal 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}.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user