mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-03 01:14:17 +02:00
Create TrangaBaseContext for common OnConfiguring implementation of Contexts
This commit is contained in:
@ -5,22 +5,10 @@ using Microsoft.EntityFrameworkCore.Diagnostics;
|
|||||||
|
|
||||||
namespace API.Schema.Contexts;
|
namespace API.Schema.Contexts;
|
||||||
|
|
||||||
public class LibraryContext(DbContextOptions<LibraryContext> options) : DbContext(options)
|
public class LibraryContext(DbContextOptions<LibraryContext> options) : TrangaBaseContext<LibraryContext>(options)
|
||||||
{
|
{
|
||||||
public DbSet<LibraryConnector> LibraryConnectors { get; set; }
|
public DbSet<LibraryConnector> LibraryConnectors { get; set; }
|
||||||
|
|
||||||
private ILog Log => LogManager.GetLogger(GetType());
|
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
||||||
{
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
optionsBuilder.EnableSensitiveDataLogging();
|
|
||||||
optionsBuilder.LogTo(s =>
|
|
||||||
{
|
|
||||||
Log.Debug(s);
|
|
||||||
}, [DbLoggerCategory.Query.Name], LogLevel.Trace, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
//LibraryConnector Types
|
//LibraryConnector Types
|
||||||
|
@ -5,19 +5,8 @@ using Microsoft.EntityFrameworkCore.Diagnostics;
|
|||||||
|
|
||||||
namespace API.Schema.Contexts;
|
namespace API.Schema.Contexts;
|
||||||
|
|
||||||
public class NotificationsContext(DbContextOptions<NotificationsContext> options) : DbContext(options)
|
public class NotificationsContext(DbContextOptions<NotificationsContext> options) : TrangaBaseContext<NotificationsContext>(options)
|
||||||
{
|
{
|
||||||
public DbSet<NotificationConnector> NotificationConnectors { get; set; }
|
public DbSet<NotificationConnector> NotificationConnectors { get; set; }
|
||||||
public DbSet<Notification> Notifications { get; set; }
|
public DbSet<Notification> Notifications { get; set; }
|
||||||
|
|
||||||
private ILog Log => LogManager.GetLogger(GetType());
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
||||||
{
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
optionsBuilder.EnableSensitiveDataLogging();
|
|
||||||
optionsBuilder.LogTo(s =>
|
|
||||||
{
|
|
||||||
Log.Debug(s);
|
|
||||||
}, [DbLoggerCategory.Query.Name], LogLevel.Trace, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Diagnostics;
|
|||||||
|
|
||||||
namespace API.Schema.Contexts;
|
namespace API.Schema.Contexts;
|
||||||
|
|
||||||
public class PgsqlContext(DbContextOptions<PgsqlContext> options) : DbContext(options)
|
public class PgsqlContext(DbContextOptions<PgsqlContext> options) : TrangaBaseContext<PgsqlContext>(options)
|
||||||
{
|
{
|
||||||
public DbSet<Job> Jobs { get; set; }
|
public DbSet<Job> Jobs { get; set; }
|
||||||
public DbSet<MangaConnector> MangaConnectors { get; set; }
|
public DbSet<MangaConnector> MangaConnectors { get; set; }
|
||||||
@ -19,17 +19,6 @@ public class PgsqlContext(DbContextOptions<PgsqlContext> options) : DbContext(op
|
|||||||
public DbSet<MangaConnectorId<Manga>> MangaConnectorToManga { get; set; }
|
public DbSet<MangaConnectorId<Manga>> MangaConnectorToManga { get; set; }
|
||||||
public DbSet<MangaConnectorId<Chapter>> MangaConnectorToChapter { get; set; }
|
public DbSet<MangaConnectorId<Chapter>> MangaConnectorToChapter { get; set; }
|
||||||
public DbSet<MetadataEntry> MetadataEntries { get; set; }
|
public DbSet<MetadataEntry> MetadataEntries { get; set; }
|
||||||
private ILog Log => LogManager.GetLogger(GetType());
|
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
||||||
{
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
optionsBuilder.EnableSensitiveDataLogging();
|
|
||||||
optionsBuilder.LogTo(s =>
|
|
||||||
{
|
|
||||||
Log.Debug(s);
|
|
||||||
}, [DbLoggerCategory.Query.Name], LogLevel.Trace, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
19
API/Schema/Contexts/TrangaBaseContext.cs
Normal file
19
API/Schema/Contexts/TrangaBaseContext.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using log4net;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||||
|
|
||||||
|
namespace API.Schema.Contexts;
|
||||||
|
|
||||||
|
public abstract class TrangaBaseContext<T>(DbContextOptions<T> options) : DbContext(options) where T : DbContext
|
||||||
|
{
|
||||||
|
private ILog Log => LogManager.GetLogger(GetType());
|
||||||
|
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
optionsBuilder.LogTo(s =>
|
||||||
|
{
|
||||||
|
Log.Debug(s);
|
||||||
|
}, Array.Empty<string>(), LogLevel.Warning, DbContextLoggerOptions.Level | DbContextLoggerOptions.Category | DbContextLoggerOptions.UtcTime);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user