Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Services.CreateScope() Missing in Asp.net Core 2.1

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/

like image 598
chobo2 Avatar asked Jun 18 '18 20:06

chobo2


People also ask

What is CreateScope in .NET core?

CreateScope also is used for any root application containers like webhost service provider.Root application providers and all objects it create will live for the life of the application.If we resolve scoped or transient services from root container instance they will be created as singletons.Instead by using scope we ...

Can we use Entity Framework 6 in ASP.NET Core?

To use Entity Framework 6, your project has to compile against . NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.

How do I get IServiceCollection from IServiceProvider?

An instance of IServiceProvider itself can be obtained by calling a BuildServiceProvider method of an IServiceCollection . IServiceCollection is a parameter of ConfigureServices method in a Startup class. It seems to be magically called with an instance of IServiceCollection by the framework.


2 Answers

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.

like image 67
Kirk Hawley Avatar answered Oct 13 '22 19:10

Kirk Hawley


You should replace this line of code:

var host = BuildWebHost(args);

with this

var host = CreateWebHostBuilder(args).Build();
like image 21
Somayeh AkbarkhahKeysami Avatar answered Oct 13 '22 21:10

Somayeh AkbarkhahKeysami