Working on Networking
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Server.Data;
|
||||
|
||||
public sealed class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<GameDbContext>
|
||||
{
|
||||
public GameDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
string cs;
|
||||
try { cs = ConnectionStringFactory.BuildMySqlFromEnv(); }
|
||||
catch
|
||||
{
|
||||
var cfg = new ConfigurationBuilder()
|
||||
.AddJsonFile("appsettings.json", optional: true)
|
||||
.AddUserSecrets<DesignTimeDbContextFactory>(optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
cs = cfg.GetConnectionString("PrimaryMySql")
|
||||
?? cfg["Database:ConnectionString"]
|
||||
?? "Server=localhost;Port=3306;Database=systemrevival;User Id=root;Password=pass;";
|
||||
}
|
||||
|
||||
var opts = new DbContextOptionsBuilder<GameDbContext>()
|
||||
.UseMySql(cs, ServerVersion.AutoDetect(cs))
|
||||
.Options;
|
||||
|
||||
return new GameDbContext(opts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user