Web Api layout
This commit is contained in:
parent
5619093f41
commit
da6d5576bf
32 changed files with 515 additions and 29 deletions
32
design/InkForge.Migrations/MigratingDbContextFactory.cs
Normal file
32
design/InkForge.Migrations/MigratingDbContextFactory.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace InkForge.Migrations;
|
||||
|
||||
public abstract class MigratingDbContextFactory<T> : IDesignTimeDbContextFactory<T>
|
||||
where T : DbContext
|
||||
{
|
||||
public T CreateDbContext(string[] args)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddCommandLine(args)
|
||||
.Build();
|
||||
|
||||
var options = new DbContextOptionsBuilder<T>();
|
||||
switch (configuration.GetValue<string>("DbProvider"))
|
||||
{
|
||||
case null:
|
||||
throw new Exception("DbProvider not set.");
|
||||
|
||||
case { } provider:
|
||||
Configure(options, configuration.GetConnectionString("DefaultConnection")!, provider);
|
||||
break;
|
||||
}
|
||||
|
||||
return CreateDbContext(options.Options);
|
||||
}
|
||||
|
||||
protected abstract void Configure(DbContextOptionsBuilder<T> optionsBuilder, string connectionString, string provider);
|
||||
|
||||
protected abstract T CreateDbContext(DbContextOptions<T> options);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue