Switch Owned value types to ComplexProperty which is better fit.
This requires fluent configuration. Also made some conversion registration context wide.
This commit is contained in:
parent
07393f57fc
commit
1a8c63808a
11 changed files with 93 additions and 54 deletions
12
IdentityShroud.Core/EFCore/Converters/DekIdConverter.cs
Normal file
12
IdentityShroud.Core/EFCore/Converters/DekIdConverter.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using IdentityShroud.Core.Security;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace IdentityShroud.Core;
|
||||
|
||||
public class DekIdConverter : ValueConverter<DekId, Guid>
|
||||
{
|
||||
public DekIdConverter()
|
||||
: base(id => id.Id, guid => new DekId(guid))
|
||||
{
|
||||
}
|
||||
}
|
||||
12
IdentityShroud.Core/EFCore/Converters/KekIdConverter.cs
Normal file
12
IdentityShroud.Core/EFCore/Converters/KekIdConverter.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using IdentityShroud.Core.Security;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace IdentityShroud.Core;
|
||||
|
||||
public class KekIdConverter : ValueConverter<KekId, Guid>
|
||||
{
|
||||
public KekIdConverter()
|
||||
: base(id => id.Id, guid => new KekId(guid))
|
||||
{
|
||||
}
|
||||
}
|
||||
55
IdentityShroud.Core/EFCore/Db.cs
Normal file
55
IdentityShroud.Core/EFCore/Db.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System.Linq.Expressions;
|
||||
using IdentityShroud.Core.Model;
|
||||
using IdentityShroud.Core.Security;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace IdentityShroud.Core;
|
||||
|
||||
public class DbConfiguration
|
||||
{
|
||||
public string ConnectionString { get; set; } = "";
|
||||
public bool LogSensitiveData { get; set; } = false;
|
||||
}
|
||||
|
||||
public class Db(
|
||||
IOptions<DbConfiguration> configuration,
|
||||
ILoggerFactory? loggerFactory)
|
||||
: DbContext
|
||||
{
|
||||
public virtual DbSet<Client> Clients { get; set; }
|
||||
public virtual DbSet<Realm> Realms { get; set; }
|
||||
public virtual DbSet<RealmKey> Keys { get; set; }
|
||||
public virtual DbSet<RealmDek> Deks { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("<connection string>");
|
||||
optionsBuilder.UseNpgsql(
|
||||
configuration.Value.ConnectionString,
|
||||
o => o.MigrationsAssembly("IdentityShroud.Migrations")); // , o => o.UseNodaTime().UseVector().MigrationsAssembly("Migrations.KnowledgeBaseDB"));
|
||||
optionsBuilder.UseSnakeCaseNamingConvention();
|
||||
|
||||
if (configuration.Value.LogSensitiveData)
|
||||
optionsBuilder.EnableSensitiveDataLogging();
|
||||
|
||||
if (loggerFactory is { } )
|
||||
{
|
||||
optionsBuilder.UseLoggerFactory(loggerFactory);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(Db).Assembly);
|
||||
}
|
||||
|
||||
protected override void ConfigureConventions(ModelConfigurationBuilder b)
|
||||
{
|
||||
base.ConfigureConventions(b);
|
||||
|
||||
b.Properties<DekId>().HaveConversion<DekIdConverter>();
|
||||
b.Properties<KekId>().HaveConversion<KekIdConverter>();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue