Skip to content

AddHostedService registration for [Hosted] classes - #38

Merged
schivei merged 11 commits into
mainfrom
feat/hosted-services
Jul 13, 2026
Merged

AddHostedService registration for [Hosted] classes#38
schivei merged 11 commits into
mainfrom
feat/hosted-services

Conversation

@schivei

@schivei schivei commented Jul 13, 2026

Copy link
Copy Markdown
Owner

PR Classification

New feature and documentation update.

PR Summary

Introduces a [Hosted] attribute to GenDI for source-generating AddHostedService registrations, with full support for property and constructor injection, and adds related diagnostics and tests.

  • Adds HostedAttribute and generator logic in GenDI and GenDI.SourceGenerator to emit AddHostedService registrations for eligible types.
  • Implements GENDISG002 diagnostic for [Hosted] types not implementing IHostedService.
  • Updates README.md, analyzer-diagnostics.md, and attributes.md with [Hosted] usage, requirements, and diagnostics.
  • Adds generator and integration tests for hosted service registration and diagnostics.
  • Refactors code formatting and updates Roslyn dependencies to 5.6.0.

SCHIVEI ELTON and others added 2 commits July 13, 2026 11:34
The GenDI source generator now recognizes the [Hosted] attribute. When a
[Hosted] class implements IHostedService — directly or through its base
chain (e.g. BackgroundService) — the generator emits
services.AddHostedService<T>(sp => ...) as part of AddGenDIServices(),
using the factory overload so [Inject] property injection and constructor
injection are honored.

If a [Hosted] class does not implement IHostedService, the generator now
reports the new GENDISG002 error and skips the type instead of emitting an
uncompilable registration.

- Add HostedServiceRegistrationTemplate and wire a hosted-registration pass
  into the build pipeline
- Thread generator Diagnostics through RegistrationBuildResult and report them
- Treat "Hosted" as a candidate attribute name for syntax discovery
- Improve HostedAttribute XML documentation
- Convert the Phase6 Worker validation app to [Hosted] + [Inject]
- Add generator unit tests and runtime integration tests for hosted services
- Document the feature and GENDISG001/GENDISG002 in README, docs, and website
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

GenDI Coverage

Line coverage: 100% (threshold 95.0%)

Source: CI/CD workflow run #226

@schivei schivei self-assigned this Jul 13, 2026
@schivei
schivei marked this pull request as ready for review July 13, 2026 14:51
@schivei
schivei merged commit 95d9950 into main Jul 13, 2026
6 checks passed
@schivei
schivei deleted the feat/hosted-services branch July 13, 2026 15:44
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant