This repository has been archived on 2023-02-13. You can view files and clone it, but cannot push or open issues or pull requests.
gswi-server/gswi/HostExtensions.cs
2022-02-20 19:04:11 +01:00

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;
}
}
}