Minor touch of code cleanup

This commit is contained in:
Cyberboss
2018-09-14 10:21:41 -04:00
parent e226cec95a
commit 05a0f60bb8
@@ -149,17 +149,21 @@ namespace Tgstation.Server.Host.Core
builder.EnableSensitiveDataLogging();
};
void AddTypedContext<TContext>() where TContext : DatabaseContext<TContext>
{
services.AddDbContext<TContext>(ConfigureDatabase);
services.AddScoped<IDatabaseContext>(x => x.GetRequiredService<TContext>());
}
var dbType = databaseConfiguration?.DatabaseType;
switch (dbType)
switch (databaseConfiguration?.DatabaseType)
{
case DatabaseType.MySql:
case DatabaseType.MariaDB:
services.AddDbContext<MySqlDatabaseContext>(ConfigureDatabase);
services.AddScoped<IDatabaseContext>(x => x.GetRequiredService<MySqlDatabaseContext>());
AddTypedContext<MySqlDatabaseContext>();
break;
case DatabaseType.SqlServer:
services.AddDbContext<SqlServerDatabaseContext>(ConfigureDatabase);
services.AddScoped<IDatabaseContext>(x => x.GetRequiredService<SqlServerDatabaseContext>());
AddTypedContext<SqlServerDatabaseContext>();
break;
default:
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Invalid {0}: {1}!", nameof(DatabaseType), dbType));