Archived
Added first app template
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using app.Data;
|
||||
|
||||
namespace app
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user