dotnet / dotnet/AspNetCore.Docs
UUF: generic-host: Add comprehensive DI example with Host setup
- Dominant language
- C#
- Stars
- 13.1k
- Forks
- 24.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 109
Description
### Description
## User feedback transferred from UUF System:
> "Where's the example? There's a lot of setup in the DI paradigm that is difficult to understand. An example is worth much more than pages of documentation. That said, the explanation appear to be thorough, but putting it all together will be difficult (it has been in my experience with DI)."
----
**The following Problem/Solution is just an AI generated recommendation and should be treated as such:**
----
## Problem Statement
The current documentation for .NET Generic Host provides thorough explanations of individual concepts and includes isolated code examples for specific features. However, it lacks a comprehensive, end-to-end example that demonstrates how to set up a complete application with dependency injection using the Generic Host. Users find it difficult to understand how all the pieces fit together, particularly regarding the DI setup process.
## Proposed Solution
Add a new section titled "Complete Example: Generic Host with Dependency Injection" that provides a full working example of a simple application using Generic Host with dependency injection. This example should demonstrate:
1. Creating and configuring the host
2. Registering different types of services (transient, scoped, singleton)
3. Consuming those services in a hosted service
4. Handling lifetime events
## Suggested Changes
Add the following section after the "Manage the host lifetime" section (around line 1060):
### Page URL
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-9.0
### Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/host/generic-host.md
### Document ID
2373a3df-6ea3-50c7-d63d-61c51d572511
### Platform Id
a08460ca-4764-dd6a-f8ee-95d128928047
### Article author
@tdykstra
### Metadata
* ID: c5f1eeee-d500-82bf-0d0a-b4e0d5d5c175
* PlatformId: a08460ca-4764-dd6a-f8ee-95d128928047
* Service: **aspnet-core**
* Sub-service: **fundamentals**
[Related Issues](https://github.com/dotnet/AspNetCore.Docs/issues?q=is%3Aissue+is%3Aopen+2373a3df-6ea3-50c7-d63d-61c51d572511)
Contributor guide
Assessment
This issue has not been assessed yet.