Skip to content

UUF: generic-host: Add comprehensive DI example with Host setupΒ #36063

@wadepickett

Description

@wadepickett

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

Metadata

Metadata

Assignees

Labels

Source - Docs.msDocs Customer feedback via GitHub Issuedoc-enhancementuser-feedbackIssues that are created from user feedback in the Unified User Feedback control.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions