Compare commits
No commits in common. "8a103831ebfe77b27aa525f2c709305950466464" and "43b6ab79343aec823eb69622010f7c0a04929416" have entirely different histories.
8a103831eb
...
43b6ab7934
45
Backend.sln
45
Backend.sln
@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.8.34330.188
|
VisualStudioVersion = 17.8.34330.188
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "Domain\Domain.csproj", "{C27FB5CD-6A70-4FB2-847A-847B34806902}"
|
||||||
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Endpoint", "Endpoint\Endpoint.csproj", "{F3A1D12E-F5B2-4339-9966-DBF869E78357}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Endpoint", "Endpoint\Endpoint.csproj", "{F3A1D12E-F5B2-4339-9966-DBF869E78357}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Elements of the solution", "Elements of the solution", "{3E087889-A4A0-4A55-A07D-7D149A5BC928}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Elements of the solution", "Elements of the solution", "{3E087889-A4A0-4A55-A07D-7D149A5BC928}"
|
||||||
@ -17,17 +19,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Elements of the solution",
|
|||||||
.gitea\workflows\test.yaml = .gitea\workflows\test.yaml
|
.gitea\workflows\test.yaml = .gitea\workflows\test.yaml
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\Application.csproj", "{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "Persistence\Persistence.csproj", "{4C1E558F-633F-438E-AC3A-61CDDED917C5}"
|
||||||
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiDto", "ApiDto\ApiDto.csproj", "{0335FA36-E137-453F-853B-916674C168FE}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiDto", "ApiDto\ApiDto.csproj", "{0335FA36-E137-453F-853B-916674C168FE}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Security", "Security\Security.csproj", "{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Security", "Security\Security.csproj", "{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}"
|
||||||
EndProject
|
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SqlData", "SqlData", "{7E7A63CD-547B-4FB4-A383-EB75298020A1}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "SqlData\Domain\Domain.csproj", "{3BFD6180-7CA7-4E85-A379-225B872439A1}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "SqlData\Application\Application.csproj", "{0B1F3656-E5B3-440C-961F-A7D004FBE9A8}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistence", "SqlData\Persistence\Persistence.csproj", "{48C9998C-ECE2-407F-835F-1A7255A5C99E}"
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -35,10 +33,22 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{C27FB5CD-6A70-4FB2-847A-847B34806902}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C27FB5CD-6A70-4FB2-847A-847B34806902}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C27FB5CD-6A70-4FB2-847A-847B34806902}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C27FB5CD-6A70-4FB2-847A-847B34806902}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F3A1D12E-F5B2-4339-9966-DBF869E78357}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E7F0A4D4-B032-4BB9-9526-1AF688F341A4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4C1E558F-633F-438E-AC3A-61CDDED917C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{0335FA36-E137-453F-853B-916674C168FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{0335FA36-E137-453F-853B-916674C168FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{0335FA36-E137-453F-853B-916674C168FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{0335FA36-E137-453F-853B-916674C168FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{0335FA36-E137-453F-853B-916674C168FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{0335FA36-E137-453F-853B-916674C168FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@ -47,27 +57,10 @@ Global
|
|||||||
{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
{47A3C065-4E1D-4B1E-AAB4-2BB8F40E56B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{3BFD6180-7CA7-4E85-A379-225B872439A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{3BFD6180-7CA7-4E85-A379-225B872439A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{3BFD6180-7CA7-4E85-A379-225B872439A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{3BFD6180-7CA7-4E85-A379-225B872439A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{0B1F3656-E5B3-440C-961F-A7D004FBE9A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{0B1F3656-E5B3-440C-961F-A7D004FBE9A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{0B1F3656-E5B3-440C-961F-A7D004FBE9A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{0B1F3656-E5B3-440C-961F-A7D004FBE9A8}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{48C9998C-ECE2-407F-835F-1A7255A5C99E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{48C9998C-ECE2-407F-835F-1A7255A5C99E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{48C9998C-ECE2-407F-835F-1A7255A5C99E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{48C9998C-ECE2-407F-835F-1A7255A5C99E}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
|
||||||
{3BFD6180-7CA7-4E85-A379-225B872439A1} = {7E7A63CD-547B-4FB4-A383-EB75298020A1}
|
|
||||||
{0B1F3656-E5B3-440C-961F-A7D004FBE9A8} = {7E7A63CD-547B-4FB4-A383-EB75298020A1}
|
|
||||||
{48C9998C-ECE2-407F-835F-1A7255A5C99E} = {7E7A63CD-547B-4FB4-A383-EB75298020A1}
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {E80A1224-87F5-4FEB-82AE-89006BE98B12}
|
SolutionGuid = {E80A1224-87F5-4FEB-82AE-89006BE98B12}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using Mirea.Api.Endpoint.Configuration.General.Attributes;
|
||||||
using Mirea.Api.DataAccess.Persistence.Common;
|
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Attributes;
|
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
|
using Mirea.Api.Endpoint.Configuration.General.Interfaces;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.General.Settings;
|
namespace Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||||
@ -17,15 +15,8 @@ public class DbSettings : IIsConfigured
|
|||||||
public DatabaseEnum TypeDatabase { get; set; }
|
public DatabaseEnum TypeDatabase { get; set; }
|
||||||
public required string ConnectionStringSql { get; set; }
|
public required string ConnectionStringSql { get; set; }
|
||||||
|
|
||||||
public DatabaseProvider DatabaseProvider =>
|
public bool IsConfigured()
|
||||||
TypeDatabase switch
|
{
|
||||||
{
|
return !string.IsNullOrEmpty(ConnectionStringSql);
|
||||||
DatabaseEnum.PostgresSql => DatabaseProvider.Postgresql,
|
}
|
||||||
DatabaseEnum.Mysql => DatabaseProvider.Mysql,
|
|
||||||
DatabaseEnum.Sqlite => DatabaseProvider.Sqlite,
|
|
||||||
_ => throw new ArgumentOutOfRangeException()
|
|
||||||
};
|
|
||||||
|
|
||||||
public bool IsConfigured() =>
|
|
||||||
!string.IsNullOrEmpty(ConnectionStringSql);
|
|
||||||
}
|
}
|
@ -115,7 +115,7 @@ public class Program
|
|||||||
builder.Services.Configure<GeneralConfig>(builder.Configuration);
|
builder.Services.Configure<GeneralConfig>(builder.Configuration);
|
||||||
|
|
||||||
builder.Services.AddApplication();
|
builder.Services.AddApplication();
|
||||||
builder.Services.AddPersistence(generalConfig?.DbSettings?.DatabaseProvider ?? DatabaseProvider.Sqlite, generalConfig?.DbSettings?.ConnectionStringSql ?? string.Empty);
|
builder.Services.AddPersistence(builder.Configuration.Get<GeneralConfig>()?.DbSettings?.ConnectionStringSql ?? string.Empty);
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
builder.Services.AddSingleton<IMaintenanceModeNotConfigureService, MaintenanceModeNotConfigureService>();
|
builder.Services.AddSingleton<IMaintenanceModeNotConfigureService, MaintenanceModeNotConfigureService>();
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
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}.");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.Common;
|
|
||||||
|
|
||||||
public static class DbContextFactory
|
|
||||||
{
|
|
||||||
public static DbContextOptionsBuilder CreateDbContext<TDbContext, TEntity>(this DbContextOptionsBuilder options, DatabaseProvider provider)
|
|
||||||
where TDbContext : BaseDbContext<TDbContext>
|
|
||||||
where TEntity : class
|
|
||||||
{
|
|
||||||
var dbContext = (TDbContext)Activator.CreateInstance(typeof(TDbContext), (DbContextOptions<TDbContext>)options.Options)!;
|
|
||||||
var configurationType = ConfigurationResolver.GetConfigurationType<TEntity>(provider);
|
|
||||||
var configurationInstance = (IEntityTypeConfiguration<TEntity>)Activator.CreateInstance(configurationType)!;
|
|
||||||
|
|
||||||
var modelBuilder = new ModelBuilder();
|
|
||||||
modelBuilder.ApplyConfiguration(configurationInstance);
|
|
||||||
dbContext.ApplyConfigurations(modelBuilder);
|
|
||||||
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.Common;
|
|
||||||
|
|
||||||
public static class ModelBuilderExtensions
|
|
||||||
{
|
|
||||||
public static void ApplyConfiguration(this ModelBuilder modelBuilder, object configuration)
|
|
||||||
{
|
|
||||||
var applyGenericMethod = typeof(ModelBuilder)
|
|
||||||
.GetMethods()
|
|
||||||
.First(m => m.Name == "ApplyConfiguration" &&
|
|
||||||
m.GetParameters().Any(p => p.ParameterType.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)));
|
|
||||||
|
|
||||||
var entityType = configuration.GetType().GetInterfaces()
|
|
||||||
.First(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>))
|
|
||||||
.GetGenericArguments()[0];
|
|
||||||
|
|
||||||
var applyConcreteMethod = applyGenericMethod.MakeGenericMethod(entityType);
|
|
||||||
applyConcreteMethod.Invoke(modelBuilder, [configuration]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +1,26 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
using Mirea.Api.DataAccess.Application.Interfaces.DbContexts.Schedule;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
|
||||||
using Mirea.Api.DataAccess.Persistence.Common;
|
|
||||||
using Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
using Mirea.Api.DataAccess.Persistence.Contexts.Schedule;
|
||||||
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations;
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence;
|
namespace Mirea.Api.DataAccess.Persistence;
|
||||||
|
|
||||||
public static class DependencyInjection
|
public static class DependencyInjection
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddPersistence(this IServiceCollection services, DatabaseProvider dbProvider, string connection)
|
public static IServiceCollection AddPersistence(this IServiceCollection services, string connection)
|
||||||
{
|
{
|
||||||
services.AddDbContext<CampusDbContext>(options =>
|
services.AddDbContext<CampusDbContext>(DbConfig);
|
||||||
UseDatabase(options).CreateDbContext<CampusDbContext, Campus>(dbProvider));
|
services.AddDbContext<DisciplineDbContext>(DbConfig);
|
||||||
services.AddDbContext<DisciplineDbContext>(options =>
|
services.AddDbContext<FacultyDbContext>(DbConfig);
|
||||||
UseDatabase(options).CreateDbContext<DisciplineDbContext, Discipline>(dbProvider));
|
services.AddDbContext<GroupDbContext>(DbConfig);
|
||||||
services.AddDbContext<FacultyDbContext>(options =>
|
services.AddDbContext<LectureHallDbContext>(DbConfig);
|
||||||
UseDatabase(options).CreateDbContext<FacultyDbContext, Faculty>(dbProvider));
|
services.AddDbContext<LessonAssociationDbContext>(DbConfig);
|
||||||
services.AddDbContext<GroupDbContext>(options =>
|
services.AddDbContext<ProfessorDbContext>(DbConfig);
|
||||||
UseDatabase(options).CreateDbContext<GroupDbContext, Group>(dbProvider));
|
services.AddDbContext<LessonDbContext>(DbConfig);
|
||||||
services.AddDbContext<LectureHallDbContext>(options =>
|
services.AddDbContext<TypeOfOccupationDbContext>(DbConfig);
|
||||||
UseDatabase(options).CreateDbContext<LectureHallDbContext, LectureHall>(dbProvider));
|
services.AddDbContext<SpecificWeekDbContext>(DbConfig);
|
||||||
services.AddDbContext<LessonAssociationDbContext>(options =>
|
|
||||||
UseDatabase(options).CreateDbContext<LessonAssociationDbContext, LessonAssociation>(dbProvider));
|
|
||||||
services.AddDbContext<ProfessorDbContext>(options =>
|
|
||||||
UseDatabase(options).CreateDbContext<ProfessorDbContext, Professor>(dbProvider));
|
|
||||||
services.AddDbContext<LessonDbContext>(options =>
|
|
||||||
UseDatabase(options).CreateDbContext<LessonDbContext, Lesson>(dbProvider));
|
|
||||||
services.AddDbContext<TypeOfOccupationDbContext>(options =>
|
|
||||||
UseDatabase(options).CreateDbContext<TypeOfOccupationDbContext, TypeOfOccupation>(dbProvider));
|
|
||||||
services.AddDbContext<SpecificWeekDbContext>(options =>
|
|
||||||
UseDatabase(options).CreateDbContext<SpecificWeekDbContext, SpecificWeek>(dbProvider));
|
|
||||||
|
|
||||||
services.AddDbContext<UberDbContext>(options =>
|
services.AddDbContext<UberDbContext>(DbConfig);
|
||||||
{
|
|
||||||
var providerNamespace = typeof(Mark).Namespace + "." + Enum.GetName(dbProvider);
|
|
||||||
|
|
||||||
var assembly = Assembly.GetExecutingAssembly();
|
|
||||||
var configurationTypes = assembly.GetTypes()
|
|
||||||
.Where(t =>
|
|
||||||
t is { IsNested: false, IsAbstract: false, Namespace: not null } &&
|
|
||||||
t.Namespace.StartsWith(providerNamespace) &&
|
|
||||||
t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEntityTypeConfiguration<>)));
|
|
||||||
|
|
||||||
var modelBuilder = new ModelBuilder();
|
|
||||||
|
|
||||||
foreach (var configurationType in configurationTypes)
|
|
||||||
{
|
|
||||||
var configurationInstance = Activator.CreateInstance(configurationType)!;
|
|
||||||
modelBuilder.ApplyConfiguration(configurationInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
var dbContext = (UberDbContext)Activator.CreateInstance(typeof(UberDbContext), (DbContextOptions<UberDbContext>)UseDatabase(options).Options)!;
|
|
||||||
dbContext.ApplyConfigurations(modelBuilder);
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddScoped<ICampusDbContext>(provider => provider.GetRequiredService<CampusDbContext>());
|
services.AddScoped<ICampusDbContext>(provider => provider.GetRequiredService<CampusDbContext>());
|
||||||
services.AddScoped<IDisciplineDbContext>(provider => provider.GetRequiredService<DisciplineDbContext>());
|
services.AddScoped<IDisciplineDbContext>(provider => provider.GetRequiredService<DisciplineDbContext>());
|
||||||
@ -72,15 +35,6 @@ public static class DependencyInjection
|
|||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
|
||||||
DbContextOptionsBuilder UseDatabase(DbContextOptionsBuilder options)
|
void DbConfig(DbContextOptionsBuilder options) => options.UseSqlite(connection);
|
||||||
{
|
|
||||||
return dbProvider switch
|
|
||||||
{
|
|
||||||
DatabaseProvider.Sqlite => options.UseSqlite(connection),
|
|
||||||
DatabaseProvider.Mysql => options.UseMySql(connection, ServerVersion.AutoDetect(connection)),
|
|
||||||
DatabaseProvider.Postgresql => options.UseNpgsql(connection),
|
|
||||||
_ => throw new ArgumentException("Unsupported database provider", Enum.GetName(dbProvider))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,13 +2,13 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public sealed class CampusConfiguration : IEntityTypeConfiguration<Campus>
|
public class CampusConfiguration : IEntityTypeConfiguration<Campus>
|
||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<Campus> builder)
|
public void Configure(EntityTypeBuilder<Campus> builder)
|
||||||
{
|
{
|
||||||
builder.ToTable("MyCampusName");
|
builder.ToTable(nameof(Campus));
|
||||||
builder.HasKey(c => c.Id);
|
builder.HasKey(c => c.Id);
|
||||||
builder.HasIndex(c => c.Id).IsUnique();
|
builder.HasIndex(c => c.Id).IsUnique();
|
||||||
builder.Property(c => c.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
builder.Property(c => c.Id).HasColumnType("INTEGER").IsRequired().ValueGeneratedOnAdd();
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class DisciplineConfiguration : IEntityTypeConfiguration<Discipline>
|
public class DisciplineConfiguration : IEntityTypeConfiguration<Discipline>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class FacultyConfiguration : IEntityTypeConfiguration<Faculty>
|
public class FacultyConfiguration : IEntityTypeConfiguration<Faculty>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class GroupConfiguration : IEntityTypeConfiguration<Group>
|
public class GroupConfiguration : IEntityTypeConfiguration<Group>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class LectureHallConfiguration : IEntityTypeConfiguration<LectureHall>
|
public class LectureHallConfiguration : IEntityTypeConfiguration<LectureHall>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class LessonAssociationConfiguration : IEntityTypeConfiguration<LessonAssociation>
|
public class LessonAssociationConfiguration : IEntityTypeConfiguration<LessonAssociation>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class LessonConfiguration : IEntityTypeConfiguration<Lesson>
|
public class LessonConfiguration : IEntityTypeConfiguration<Lesson>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class ProfessorConfiguration : IEntityTypeConfiguration<Professor>
|
public class ProfessorConfiguration : IEntityTypeConfiguration<Professor>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class SpecificWeekConfiguration : IEntityTypeConfiguration<SpecificWeek>
|
public class SpecificWeekConfiguration : IEntityTypeConfiguration<SpecificWeek>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Sqlite.Schedule;
|
namespace Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
|
|
||||||
public class TypeOfOccupationConfiguration : IEntityTypeConfiguration<TypeOfOccupation>
|
public class TypeOfOccupationConfiguration : IEntityTypeConfiguration<TypeOfOccupation>
|
||||||
{
|
{
|
@ -1,11 +1,10 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Mirea.Api.DataAccess.Domain.Schedule;
|
using Mirea.Api.DataAccess.Domain.Schedule;
|
||||||
using Mirea.Api.DataAccess.Persistence.Common;
|
using Mirea.Api.DataAccess.Persistence.EntityTypeConfigurations.Schedule;
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Mirea.Api.DataAccess.Persistence;
|
namespace Mirea.Api.DataAccess.Persistence;
|
||||||
|
|
||||||
public class UberDbContext(DbContextOptions<UberDbContext> options) : BaseDbContext<UberDbContext>(options)
|
public class UberDbContext(DbContextOptions<UberDbContext> options) : DbContext(options)
|
||||||
{
|
{
|
||||||
public DbSet<Campus> Campuses { get; set; } = null!;
|
public DbSet<Campus> Campuses { get; set; } = null!;
|
||||||
public DbSet<Discipline> Disciplines { get; set; } = null!;
|
public DbSet<Discipline> Disciplines { get; set; } = null!;
|
||||||
@ -20,7 +19,17 @@ public class UberDbContext(DbContextOptions<UberDbContext> options) : BaseDbCont
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
modelBuilder.ApplyConfiguration(new CampusConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new DisciplineConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new FacultyConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new GroupConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new LectureHallConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new LessonConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new ProfessorConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new LessonAssociationConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new TypeOfOccupationConfiguration());
|
||||||
|
modelBuilder.ApplyConfiguration(new SpecificWeekConfiguration());
|
||||||
|
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user