sync full source from private myoffice

This commit is contained in:
myoffice-sync
2026-08-05 10:55:09 +00:00
parent 874796c860
commit 405abdfe69
714 changed files with 70352 additions and 234 deletions
@@ -0,0 +1,50 @@
namespace MyOffice.DbContext;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
public static class DbContextServiceCollectionExtensions
{
public static IServiceCollection AddAppDbContext(
this IServiceCollection services,
ConnectionConfiguration connection
)
{
services.AddSingleton(connection);
services.AddDbContext<AppDbContext>((_, options) =>
{
ConfigureDbContextOptions(options, connection);
});
return services;
}
public static void ConfigureDbContextOptions(
DbContextOptionsBuilder options,
ConnectionConfiguration connection
)
{
if (!Enum.TryParse<AppDbContextProvidersEnum>(connection.Provider, ignoreCase: true, out var provider))
throw new InvalidOperationException($"No such provider: [{connection.Provider}]");
switch (provider)
{
case AppDbContextProvidersEnum.npgsql:
options.UseNpgsql(connection.ConnectionString, x =>
x.MigrationsAssembly("MyOffice.Migrations.Postgres"));
break;
case AppDbContextProvidersEnum.sqlite:
options.UseSqlite(connection.ConnectionString, x =>
x.MigrationsAssembly("MyOffice.Migrations.Sqlite"));
break;
default:
throw new NotSupportedException($"No such provider: [{connection.Provider}]");
}
#if DEBUG
options.EnableSensitiveDataLogging();
options.EnableDetailedErrors();
#endif
}
}