You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This article introduces the .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>) and provides guidance on how to use it.
15
+
The ASP.NET Core templates create a .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>).
16
16
17
-
## What's a host?
17
+
## Host definition
18
18
19
19
A *host* is an object that encapsulates an app's resources, such as:
20
20
@@ -27,16 +27,33 @@ When a host starts, it calls `IHostedService.StartAsync` on each implementation
27
27
28
28
The main reason for including all of the app's interdependent resources in one object is lifetime management: control over app startup and graceful shutdown.
29
29
30
-
In versions of ASP.NET Core earlier than 3.0, the [Web Host](xref:fundamentals/host/web-host) is used for HTTP workloads. The Web Host is no longer recommended for web apps and remains available only for backward compatibility.
31
-
32
30
## Set up a host
33
31
34
32
The host is typically configured, built, and run by code in the `Program` class. The `Main` method:
35
33
36
34
* Calls a `CreateHostBuilder` method to create and configure a builder object.
37
35
* Calls `Build` and `Run` methods on the builder object.
38
36
39
-
Here's *Program.cs* code for a non-HTTP workload, with a single `IHostedService` implementation added to the DI container.
37
+
The ASP.NET Core web templates generate the following code to create a host:
The following code creates a non-HTTP workload with a `IHostedService` implementation added to the DI container.
40
57
41
58
```csharp
42
59
publicclassProgram
@@ -970,9 +987,9 @@ public class MyClass
970
987
971
988
::: moniker range=">= aspnetcore-5.0"
972
989
973
-
This article introduces the .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>) and provides guidance on how to use it.
990
+
The ASP.NET Core templates create a .NET Core Generic Host (<xref:Microsoft.Extensions.Hosting.HostBuilder>).
974
991
975
-
## What's a host?
992
+
## Host definition
976
993
977
994
A *host* is an object that encapsulates an app's resources, such as:
978
995
@@ -985,16 +1002,33 @@ When a host starts, it calls `IHostedService.StartAsync` on each implementation
985
1002
986
1003
The main reason for including all of the app's interdependent resources in one object is lifetime management: control over app startup and graceful shutdown.
987
1004
988
-
In versions of ASP.NET Core earlier than 3.0, the [Web Host](xref:fundamentals/host/web-host) is used for HTTP workloads. The Web Host is no longer recommended for web apps and remains available only for backward compatibility.
989
-
990
1005
## Set up a host
991
1006
992
1007
The host is typically configured, built, and run by code in the `Program` class. The `Main` method:
993
1008
994
1009
* Calls a `CreateHostBuilder` method to create and configure a builder object.
995
1010
* Calls `Build` and `Run` methods on the builder object.
996
1011
997
-
Here's *Program.cs* code for a non-HTTP workload, with a single `IHostedService` implementation added to the DI container.
1012
+
The ASP.NET Core web templates generate the following code to create a host:
0 commit comments