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/

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.

-Kirk

Services.CreateScope() Missing in Asp.net Core 2.1, 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  All the features of ASP.NET Core 2.0 and Entity Framework Core 2.0 are included in the metapackage. ASP.NET Core 2.0 projects targeting .NET Framework should continue to reference individual NuGet packages. Update the Version attribute of each <PackageReference /> node to 2.0.0. For example,

You should replace this line of code:

var host = BuildWebHost(args);

with this

var host = CreateWebHostBuilder(args).Build();

Services.CreateScope() in IWebhost not working anymore · Issue , The latter don't work. How can I migrate the database during startup like in the previous version? Version of Microsoft.AspNetCore.Mvc or  IServiceProvider does not contain definition for CreateScope #2213. IServiceProvider does not contain definition for Fix EF migrations in ASP.NET 2

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>();

ServiceProviderServiceExtensions.CreateScope(IServiceProvider , A IServiceScope that can be used to resolve scoped services. Applies to .NET Platform Extensions. 3.1 3.0 2.2 2.1 2.0 1.1  Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

ASP.NET Core Web Host, ASP.NET Core Dependency Injection - Shawn Wildermuth. I was missing and my suggestion would actually just leak a context object. Scoped: Shared within a single request (or Service Scope). You can see that the IServiceCollection supports AddXXX() methods for these three CreateScope()) { // . I am starting a Razor pages project in ASP.NET Core 2.1. I am trying to use SQLite but when configuring the database only SQL Server seems to be an option. Startup.cs using Microsoft.AspNetCore.B

ASP.NET Core Dependency Injection, ASP.NET Core 2.1 Configuration Dependency Injection ~ 10 min read. The configuration system in ASP.NET ASP.NET Core and the difference between IOptions<> and CreateScope() and resolve the service directly. I understand that you want to get an instance of your DBContext. And execute some code with it. Right here I will give you an example to auto seed the database during ASP.NET Core 3.1 start up. You can try the following code or try the way of soloing your problem. First, copy the following code to your project:

The dangers and gotchas of using scoped services in , Can anyone provide basic code for how to seed a db in dot net core 2.1 ? In 2.0, I Start().Services.CreateScope()) { var services = scope. ASP.NET Core 2.1 and later provides ASP.NET Core Identity as a Razor Class Library. Applications that include Identity can apply the scaffolder to selectively add the source code contained in the Identity Razor Class Library (RCL). You might want to generate source code so you can modify the code and change the behavior.

Comments
  • Have you used Microsoft.Extensions.DependencyInjection?