Reputation: 85765
What replaced Services.CreateScope() in 2.1?
I am trying to follow this tutorial but it seems like stuff has changed quite a bit
https://dotnetthoughts.net/seed-database-in-aspnet-core/
Upvotes: 7
Views: 7291
Reputation: 341
I had the same problem with the ASP.NET Core MVC with Entity Framework Core tutorial, written for .NET Core 2, trying to run it with .NET Core 2.1. It worked fine once I added
using Microsoft.Extensions.DependencyInjection;
to the problem file, in my case Program.cs.
Upvotes: 21
Reputation: 543
public static void Main(string[] args)
{
var host = CreateWebHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
try
{
//
}
catch (System.Exception ex)
{
///
}
}
host.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
Upvotes: 0
Reputation: 79
You should replace this line of code:
var host = BuildWebHost(args);
with this
var host = CreateWebHostBuilder(args).Build();
Upvotes: 6