From f79c7c7db9e6693aa78858a7ad89c1a72c9cb273 Mon Sep 17 00:00:00 2001 From: Polianin Nikita Date: Thu, 30 May 2024 20:11:18 +0300 Subject: [PATCH] refactor: use wrap DbContext --- SqlData/Persistence/Contexts/Schedule/CampusDbContext.cs | 7 ++++--- .../Persistence/Contexts/Schedule/DisciplineDbContext.cs | 7 ++++--- SqlData/Persistence/Contexts/Schedule/FacultyDbContext.cs | 7 ++++--- SqlData/Persistence/Contexts/Schedule/GroupDbContext.cs | 7 ++++--- .../Persistence/Contexts/Schedule/LectureHallDbContext.cs | 7 ++++--- .../Contexts/Schedule/LessonAssociationDbContext.cs | 7 ++++--- SqlData/Persistence/Contexts/Schedule/LessonDbContext.cs | 7 ++++--- .../Persistence/Contexts/Schedule/ProfessorDbContext.cs | 7 ++++--- .../Persistence/Contexts/Schedule/SpecificWeekDbContext.cs | 7 ++++--- .../Contexts/Schedule/TypeOfOccupationDbContext.cs | 7 ++++--- 10 files changed, 40 insertions(+), 30 deletions(-) diff --git a/SqlData/Persistence/Contexts/Schedule/CampusDbContext.cs b/SqlData/Persistence/Contexts/Schedule/CampusDbContext.cs index 30a9d56..d93e3d9 100644 --- a/SqlData/Persistence/Contexts/Schedule/CampusDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/CampusDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class CampusDbContext(DbContextOptions options) : DbContext(options), ICampusDbContext +public class CampusDbContext(DbContextOptions options) : BaseDbContext(options), ICampusDbContext { public DbSet Campuses { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new CampusConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/DisciplineDbContext.cs b/SqlData/Persistence/Contexts/Schedule/DisciplineDbContext.cs index d0a5612..d9ec9e1 100644 --- a/SqlData/Persistence/Contexts/Schedule/DisciplineDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/DisciplineDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class DisciplineDbContext(DbContextOptions options) : DbContext(options), IDisciplineDbContext +public sealed class DisciplineDbContext(DbContextOptions options) : BaseDbContext(options), IDisciplineDbContext { public DbSet Disciplines { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new DisciplineConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/FacultyDbContext.cs b/SqlData/Persistence/Contexts/Schedule/FacultyDbContext.cs index ab6a45c..98323a6 100644 --- a/SqlData/Persistence/Contexts/Schedule/FacultyDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/FacultyDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class FacultyDbContext(DbContextOptions options) : DbContext(options), IFacultyDbContext +public sealed class FacultyDbContext(DbContextOptions options) : BaseDbContext(options), IFacultyDbContext { public DbSet Faculties { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new FacultyConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/GroupDbContext.cs b/SqlData/Persistence/Contexts/Schedule/GroupDbContext.cs index 5d61c70..e6bcc5e 100644 --- a/SqlData/Persistence/Contexts/Schedule/GroupDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/GroupDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class GroupDbContext(DbContextOptions options) : DbContext(options), IGroupDbContext +public sealed class GroupDbContext(DbContextOptions options) : BaseDbContext(options), IGroupDbContext { public DbSet Groups { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new GroupConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/LectureHallDbContext.cs b/SqlData/Persistence/Contexts/Schedule/LectureHallDbContext.cs index 67841a1..4253309 100644 --- a/SqlData/Persistence/Contexts/Schedule/LectureHallDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/LectureHallDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class LectureHallDbContext(DbContextOptions options) : DbContext(options), ILectureHallDbContext +public sealed class LectureHallDbContext(DbContextOptions options) : BaseDbContext(options), ILectureHallDbContext { public DbSet LectureHalls { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new LectureHallConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/LessonAssociationDbContext.cs b/SqlData/Persistence/Contexts/Schedule/LessonAssociationDbContext.cs index 773bc8a..ae6be39 100644 --- a/SqlData/Persistence/Contexts/Schedule/LessonAssociationDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/LessonAssociationDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class LessonAssociationDbContext(DbContextOptions options) : DbContext(options), ILessonAssociationDbContext +public sealed class LessonAssociationDbContext(DbContextOptions options) : BaseDbContext(options), ILessonAssociationDbContext { public DbSet LessonAssociations { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/LessonDbContext.cs b/SqlData/Persistence/Contexts/Schedule/LessonDbContext.cs index d2dfcae..e727041 100644 --- a/SqlData/Persistence/Contexts/Schedule/LessonDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/LessonDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class LessonDbContext(DbContextOptions options) : DbContext(options), ILessonDbContext +public sealed class LessonDbContext(DbContextOptions options) : BaseDbContext(options), ILessonDbContext { public DbSet Lessons { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new LessonConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/ProfessorDbContext.cs b/SqlData/Persistence/Contexts/Schedule/ProfessorDbContext.cs index fcd51c6..75924ff 100644 --- a/SqlData/Persistence/Contexts/Schedule/ProfessorDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/ProfessorDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class ProfessorDbContext(DbContextOptions options) : DbContext(options), IProfessorDbContext +public sealed class ProfessorDbContext(DbContextOptions options) : BaseDbContext(options), IProfessorDbContext { public DbSet Professors { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new ProfessorConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/SpecificWeekDbContext.cs b/SqlData/Persistence/Contexts/Schedule/SpecificWeekDbContext.cs index b3601bd..20bbab7 100644 --- a/SqlData/Persistence/Contexts/Schedule/SpecificWeekDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/SpecificWeekDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class SpecificWeekDbContext(DbContextOptions options) : DbContext(options), ISpecificWeekDbContext +public sealed class SpecificWeekDbContext(DbContextOptions options) : BaseDbContext(options), ISpecificWeekDbContext { public DbSet SpecificWeeks { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new SpecificWeekConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/SqlData/Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs b/SqlData/Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs index b47ac61..ae49d35 100644 --- a/SqlData/Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs +++ b/SqlData/Persistence/Contexts/Schedule/TypeOfOccupationDbContext.cs @@ -1,17 +1,18 @@ using Microsoft.EntityFrameworkCore; using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule; using Mirea.Api.DataAccess.Domain.Schedule; -using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule; +using Mirea.Api.DataAccess.Persistence.Common; +using System.Reflection; namespace Mirea.Api.DataAccess.Persistence.Contexts.Schedule; -public class TypeOfOccupationDbContext(DbContextOptions options) : DbContext(options), ITypeOfOccupationDbContext +public sealed class TypeOfOccupationDbContext(DbContextOptions options) : BaseDbContext(options), ITypeOfOccupationDbContext { public DbSet TypeOfOccupations { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration()); + modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); base.OnModelCreating(modelBuilder); } } \ No newline at end of file