1
0
mirror of https://github.com/bitwarden/server synced 2025-12-15 15:53:59 +00:00

Revert filescoped (#2227)

* Revert "Add git blame entry (#2226)"

This reverts commit 239286737d.

* Revert "Turn on file scoped namespaces (#2225)"

This reverts commit 34fb4cca2a.
This commit is contained in:
Justin Baur
2022-08-29 15:53:48 -04:00
committed by GitHub
parent 239286737d
commit bae03feffe
1208 changed files with 74317 additions and 73126 deletions

View File

@@ -5,61 +5,62 @@ using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Infrastructure.EntityFramework;
public static class EntityFrameworkServiceCollectionExtensions
namespace Bit.Infrastructure.EntityFramework
{
public static void AddEFRepositories(this IServiceCollection services, bool selfHosted, string connectionString,
SupportedDatabaseProviders provider)
public static class EntityFrameworkServiceCollectionExtensions
{
if (string.IsNullOrWhiteSpace(connectionString))
public static void AddEFRepositories(this IServiceCollection services, bool selfHosted, string connectionString,
SupportedDatabaseProviders provider)
{
throw new Exception($"Database provider type {provider} was selected but no connection string was found.");
}
LinqToDBForEFTools.Initialize();
services.AddAutoMapper(typeof(UserRepository));
services.AddDbContext<DatabaseContext>(options =>
{
if (provider == SupportedDatabaseProviders.Postgres)
if (string.IsNullOrWhiteSpace(connectionString))
{
options.UseNpgsql(connectionString);
// Handle NpgSql Legacy Support for `timestamp without timezone` issue
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
throw new Exception($"Database provider type {provider} was selected but no connection string was found.");
}
else if (provider == SupportedDatabaseProviders.MySql)
LinqToDBForEFTools.Initialize();
services.AddAutoMapper(typeof(UserRepository));
services.AddDbContext<DatabaseContext>(options =>
{
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
}
});
services.AddSingleton<ICipherRepository, CipherRepository>();
services.AddSingleton<ICollectionCipherRepository, CollectionCipherRepository>();
services.AddSingleton<ICollectionRepository, CollectionRepository>();
services.AddSingleton<IDeviceRepository, DeviceRepository>();
services.AddSingleton<IEmergencyAccessRepository, EmergencyAccessRepository>();
services.AddSingleton<IFolderRepository, FolderRepository>();
services.AddSingleton<IGrantRepository, GrantRepository>();
services.AddSingleton<IGroupRepository, GroupRepository>();
services.AddSingleton<IInstallationRepository, InstallationRepository>();
services.AddSingleton<IMaintenanceRepository, MaintenanceRepository>();
services.AddSingleton<IOrganizationRepository, OrganizationRepository>();
services.AddSingleton<IOrganizationApiKeyRepository, OrganizationApiKeyRepository>();
services.AddSingleton<IOrganizationConnectionRepository, OrganizationConnectionRepository>();
services.AddSingleton<IOrganizationSponsorshipRepository, OrganizationSponsorshipRepository>();
services.AddSingleton<IOrganizationUserRepository, OrganizationUserRepository>();
services.AddSingleton<IPolicyRepository, PolicyRepository>();
services.AddSingleton<ISendRepository, SendRepository>();
services.AddSingleton<ISsoConfigRepository, SsoConfigRepository>();
services.AddSingleton<ISsoUserRepository, SsoUserRepository>();
services.AddSingleton<ITaxRateRepository, TaxRateRepository>();
services.AddSingleton<ITransactionRepository, TransactionRepository>();
services.AddSingleton<IUserRepository, UserRepository>();
services.AddSingleton<IProviderRepository, ProviderRepository>();
services.AddSingleton<IProviderUserRepository, ProviderUserRepository>();
services.AddSingleton<IProviderOrganizationRepository, ProviderOrganizationRepository>();
if (provider == SupportedDatabaseProviders.Postgres)
{
options.UseNpgsql(connectionString);
// Handle NpgSql Legacy Support for `timestamp without timezone` issue
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
}
else if (provider == SupportedDatabaseProviders.MySql)
{
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
}
});
services.AddSingleton<ICipherRepository, CipherRepository>();
services.AddSingleton<ICollectionCipherRepository, CollectionCipherRepository>();
services.AddSingleton<ICollectionRepository, CollectionRepository>();
services.AddSingleton<IDeviceRepository, DeviceRepository>();
services.AddSingleton<IEmergencyAccessRepository, EmergencyAccessRepository>();
services.AddSingleton<IFolderRepository, FolderRepository>();
services.AddSingleton<IGrantRepository, GrantRepository>();
services.AddSingleton<IGroupRepository, GroupRepository>();
services.AddSingleton<IInstallationRepository, InstallationRepository>();
services.AddSingleton<IMaintenanceRepository, MaintenanceRepository>();
services.AddSingleton<IOrganizationRepository, OrganizationRepository>();
services.AddSingleton<IOrganizationApiKeyRepository, OrganizationApiKeyRepository>();
services.AddSingleton<IOrganizationConnectionRepository, OrganizationConnectionRepository>();
services.AddSingleton<IOrganizationSponsorshipRepository, OrganizationSponsorshipRepository>();
services.AddSingleton<IOrganizationUserRepository, OrganizationUserRepository>();
services.AddSingleton<IPolicyRepository, PolicyRepository>();
services.AddSingleton<ISendRepository, SendRepository>();
services.AddSingleton<ISsoConfigRepository, SsoConfigRepository>();
services.AddSingleton<ISsoUserRepository, SsoUserRepository>();
services.AddSingleton<ITaxRateRepository, TaxRateRepository>();
services.AddSingleton<ITransactionRepository, TransactionRepository>();
services.AddSingleton<IUserRepository, UserRepository>();
services.AddSingleton<IProviderRepository, ProviderRepository>();
services.AddSingleton<IProviderUserRepository, ProviderUserRepository>();
services.AddSingleton<IProviderOrganizationRepository, ProviderOrganizationRepository>();
if (selfHosted)
{
services.AddSingleton<IEventRepository, EventRepository>();
if (selfHosted)
{
services.AddSingleton<IEventRepository, EventRepository>();
}
}
}
}