From 142577035a4f0a6df2e24b244faf978694cf88ef Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Fri, 15 Sep 2023 16:24:47 -0700 Subject: [PATCH] Add note about resolving scoped services during migration (#30377) * Add note about resolving scoped services during migration Addresses https://github.com/dotnet/aspnetcore/issues/38326 * Update aspnetcore/migration/50-to-60.md Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --------- Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com> --- aspnetcore/migration/50-to-60.md | 1 + 1 file changed, 1 insertion(+) diff --git a/aspnetcore/migration/50-to-60.md b/aspnetcore/migration/50-to-60.md index 8ea018d537..1e0c10668b 100644 --- a/aspnetcore/migration/50-to-60.md +++ b/aspnetcore/migration/50-to-60.md @@ -187,6 +187,7 @@ When using `Startup` with the new minimal hosting model, keep in mind the follow * The endpoint routing middleware wraps the entire middleware pipeline, therefore there's no need to have explicit calls to `UseRouting` or `UseEndpoints` to register routes. `UseRouting` can still be used to specify where route matching happens, but `UseRouting` doesn't need to be explicitly called if routes should be matched at the beginning of the middleware pipeline. * The [pipeline](xref:fundamentals/middleware/index) is created before any runs, therefore exceptions caused while building the pipeline aren't visible to the `IStartupFilter` call chain. * Some tools, such as EF migrations, use [`Program.CreateHostBuilder`](xref:fundamentals/host/generic-host) to access the app's `IServiceProvider` to execute custom logic in the context of the app. These tools have been updated to use a new technique to execute custom logic in the context of the app. [Entity Framework Migrations](/ef/core/managing-schemas/migrations/) is an example of a tool that uses `Program.CreateHostBuilder` in this way. We're working to make sure tools are updated to use the new model. +* Unlike the `Startup` class, the minimal host doesn't automatically configure a DI scope when instantiating the service provider. For contexts where a scope is required, it is necessary to invoke with [IServiceScopeFactory.CreateScope](xref:Microsoft.Extensions.DependencyInjection.IServiceScopeFactory.CreateScope%2A) to instantiate a new scope. For more information, see [how to resolve a service at app startup](xref:fundamentals/dependency-injection#resolve-a-service-at-app-start-up). * It's ***not*** possible to [change any host settings such as app name, environment, or the content root](xref:migration/50-to-60-samples#ccr) after the creation of the . For detailed instructions on changing host settings, see [Customize `IHostBuilder` or `IWebHostBuilder`](xref:migration/50-to-60-samples#cii). The following highlighted APIs throw an exception: