Skip to content

Commit eb00116

Browse files
authored
RM2
1 parent e3bb59f commit eb00116

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ReadMe.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ If you have other applications such as ASP.NET in the entire project and want to
943943
var builder = Host.CreateApplicationBuilder(); // don't pass args.
944944
945945
using var host = builder.Build(); // use using for host lifetime
946-
ConsoleApp.ServiceProvider = host.Services; // use host ServiceProvider
946+
using var scope = host.Services.CreateScope(); // create execution scope
947+
ConsoleApp.ServiceProvider = scope.ServiceProvider; // use host scoped ServiceProvider
947948
948949
ConsoleApp.Run(args, ([FromServices] ILogger<Program> logger) => logger.LogInformation("Hello World!"));
949950
```
@@ -987,7 +988,8 @@ v4 was running on top of `Microsoft.Extensions.Hosting`, so build a Host in the
987988

988989
```csharp
989990
using var host = Host.CreateDefaultBuilder().Build(); // use using for host lifetime
990-
ConsoleApp.ServiceProvider = host.ServiceProvider;
991+
using var scope = host.Services.CreateScope(); // create execution scope
992+
ConsoleApp.ServiceProvider = scope.ServiceProvider;
991993
```
992994

993995
* `var app = ConsoleApp.Create(args); app.Run();` -> `var app = ConsoleApp.Create(); app.Run(args);`

0 commit comments

Comments
 (0)