File tree 1 file changed +4
-2
lines changed
1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -943,7 +943,8 @@ If you have other applications such as ASP.NET in the entire project and want to
943
943
var builder = Host .CreateApplicationBuilder (); // don't pass args.
944
944
945
945
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
947
948
948
949
ConsoleApp .Run (args , ([FromServices ] ILogger <Program > logger ) => logger .LogInformation (" Hello World!" ));
949
950
```
@@ -987,7 +988,8 @@ v4 was running on top of `Microsoft.Extensions.Hosting`, so build a Host in the
987
988
988
989
``` csharp
989
990
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 ;
991
993
```
992
994
993
995
* ` var app = ConsoleApp.Create(args); app.Run(); ` -> ` var app = ConsoleApp.Create(); app.Run(args); `
You can’t perform that action at this time.
0 commit comments