31 lines
826 B
C#
31 lines
826 B
C#
|
using System;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using Microsoft.Extensions.Hosting;
|
||
|
using gswi.Data;
|
||
|
|
||
|
namespace gswi
|
||
|
{
|
||
|
public static class HostExtensions
|
||
|
{
|
||
|
public static IHost SeedData(this IHost host)
|
||
|
{
|
||
|
using (var scope = host.Services.CreateScope())
|
||
|
{
|
||
|
var services = scope.ServiceProvider;
|
||
|
var context = services.GetService<DatabaseContext>();
|
||
|
|
||
|
// now we have the DbContext. Run migrations
|
||
|
context.Database.Migrate();
|
||
|
|
||
|
#if DEBUG
|
||
|
// now that the database is up to date. Let's seed
|
||
|
new DataSeeder(context).SeedData();
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
return host;
|
||
|
}
|
||
|
}
|
||
|
}
|