mirror of
https://github.com/NexusForever/NexusForever
synced 2026-08-14 00:26:05 -04:00
26 lines
1.1 KiB
C#
26 lines
1.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using NexusForever.Database.Configuration;
|
|
|
|
namespace NexusForever.Database
|
|
{
|
|
public static class Extensions
|
|
{
|
|
public static DbContextOptionsBuilder UseConfiguration(this DbContextOptionsBuilder optionsBuilder, IDatabaseConfig databaseConfiguration, DatabaseType databaseType)
|
|
{
|
|
var connectionString = databaseConfiguration.GetConnectionString(databaseType);
|
|
switch (connectionString.Provider)
|
|
{
|
|
case DatabaseProvider.MySql:
|
|
optionsBuilder.UseMySql(connectionString.ConnectionString, ServerVersion.AutoDetect(connectionString.ConnectionString), b =>
|
|
{
|
|
b.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
|
|
});
|
|
break;
|
|
default:
|
|
throw new NotSupportedException($"The requested database provider: {connectionString.Provider:G} is not supported.");
|
|
}
|
|
return optionsBuilder;
|
|
}
|
|
}
|
|
}
|