Skip to content

Conversation

@ysmoradi
Copy link
Member

@ysmoradi ysmoradi commented Nov 29, 2025

closes #11768

Summary by CodeRabbit

  • Refactor

    • Dependency injection pattern updated: replaced AutoInject field-level injection with lazy scoped service resolution via ScopedServices.
    • Removed automatic Razor component field injection support.
  • Documentation

    • Updated Dependency Injection & Service Registration documentation with ScopedServices patterns and "Owned services" guidance.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 29, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The AutoInject source generator is refactored to remove Razor component-specific code generation logic. An enum, handler class, and related helper methods are eliminated. The source generator now uses a single code path for all classes. The TodoPage component is updated to use lazy ScopedServices resolution instead of AutoInject field injection.

Changes

Cohort / File(s) Summary
Enum and Handler Removal
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectClassType.cs, src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectRazorComponentHandler.cs
Removed AutoInjectClassType enum with RazorComponent and NormalClass members. Removed entire AutoInjectRazorComponentHandler class including Generate, GenerateInjectableProperties, and GenerateProperty methods that produced injectable property code for Razor components.
Source Generator Consolidation
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectSourceGenerator.cs
Simplified GenerateSource to always delegate to AutoInjectNormalClassHandler.Generate. Removed FigureOutTypeOfEnvironment and IsClassIsRazorComponent helper methods. Eliminated conditional dispatch logic based on class type classification.
Documentation Update
src/Templates/Boilerplate/Bit.Boilerplate/.docs/09- Dependency Injection & Service Registration.md
Added "Owned services" section documenting default Blazor component service lifetimes, ScopedServices usage for automatic disposal, and code example for obtaining scoped services.
Component Example Migration
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/TodoPage.razor.cs
Replaced AutoInject field-level injection of Keyboard with lazy property: Keyboard keyboard => field ??= ScopedServices.GetRequiredService<Keyboard>();. Removed DisposeAsync override that explicitly disposed the Keyboard instance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

  • Verify that removal of AutoInjectRazorComponentHandler and related enum doesn't break any other files or usages throughout the codebase
  • Confirm the consolidated single code path in AutoInjectSourceGenerator.cs correctly handles all previously-differentiated scenarios
  • Review the TodoPage.razor.cs migration to ensure lazy resolution semantics and lifecycle behavior align with design intent
  • Check that ScopedServices availability is guaranteed in components where this pattern is applied

Poem

🐰 One path now shines where two once stood,
AutoInject streamlined, simplified for good!
ScopedServices takes the wheel with grace,
Lazy loading quickens the component's race.
One generator to bind them all— neat and clean! ✨

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The changes partially address issue #11741. While the PR removes Razor component-specific code generation and transitions to ScopedServices for owned services, it does not implement primary constructor injection as required. Implement primary constructor injection for both services and Blazor components to fully meet issue #11741 requirements [#11741].
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ⚠️ Warning The PR title 'Add doc for OwningComponentBase to bit Boilerplate (#11768)' does not match the actual changes. The PR removes AutoInject functionality and replaces it with ScopedServices, but the title suggests only documentation was added. Update the title to reflect the main change, such as 'Refactor AutoInject to use ScopedServices for owned services in Boilerplate' or 'Replace AutoInject with ScopedServices-based dependency resolution'.
✅ Passed checks (2 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed All changes are within scope of improving the AutoInject feature. The removal of Razor-specific handling, the simplification to NormalClass only, and the transition to ScopedServices align with the stated objectives.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between d851f67 and 03c0e8c.

📒 Files selected for processing (5)
  • src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectClassType.cs (0 hunks)
  • src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectRazorComponentHandler.cs (0 hunks)
  • src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectSourceGenerator.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/.docs/09- Dependency Injection & Service Registration.md (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/TodoPage.razor.cs (1 hunks)
💤 Files with no reviewable changes (2)
  • src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectClassType.cs
  • src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectRazorComponentHandler.cs
🧰 Additional context used
🧬 Code graph analysis (2)
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectSourceGenerator.cs (1)
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectNormalClassHandler.cs (2)
  • AutoInjectNormalClassHandler (8-123)
  • Generate (10-36)
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/TodoPage.razor.cs (1)
src/Butil/Bit.Butil/Publics/Keyboard.cs (1)
  • Keyboard (10-100)
🪛 LanguageTool
src/Templates/Boilerplate/Bit.Boilerplate/.docs/09- Dependency Injection & Service Registration.md

[grammar] ~273-~273: Ensure spelling is correct
Context: ...es.GetRequiredService(); Insetad of csharp [AutoInject] private Key...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build Bit.Templates
🔇 Additional comments (3)
src/Templates/Boilerplate/Bit.Boilerplate/.docs/09- Dependency Injection & Service Registration.md (1)

253-284: Well-documented pattern for owned services.

The new section clearly explains when and how to use ScopedServices for automatic disposal of owned services in Blazor components. The before/after code examples effectively demonstrate the improvement.

src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectSourceGenerator.cs (1)

83-86: I'm unable to complete the automated verification due to persistent repository access issues. Let me provide a rewritten review comment that addresses this limitation:


Verify Razor component migration to ScopedServices pattern.

The removal of Razor component-specific code paths and shift to a single NormalClassHandler approach aligns with the PR objective to use primary constructor injection uniformly. This is a cleaner architecture.

However, automated verification of remaining [AutoInject] usage in Razor components was not possible. Manual verification is required to confirm that:

  1. No orphaned [AutoInject] attributes remain in Razor component code-behind files (in Components/ and Pages/ directories)
  2. Existing components have been migrated to the ScopedServices pattern shown in TodoPage.razor.cs

Search for remaining [AutoInject] usage in .cs files within component directories to ensure complete migration.

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/TodoPage.razor.cs (1)

10-11: Manual verification required — unable to access repository to confirm C# 13 and base class configuration.

The repository clone failed, preventing direct verification of the two concerns raised. However, web search confirms that the field keyword is a valid C# 13 feature with the syntax pattern shown in your code. The lazy initialization pattern (field ??= ...) is correctly used within a property accessor expression.

To complete the verification, you will need to manually confirm:

  1. C# 13 is enabled: Check your .csproj file(s) for <LangVersion>13</LangVersion> or <LangVersion>preview</LangVersion>
  2. ScopedServices is available: Verify that the base class of TodoPage (likely AppComponentBase or AppPageBase) defines or inherits the ScopedServices property

@ysmoradi ysmoradi changed the title Improve bit SourceGenerator's AutoInject (#11741) Add doc for OwningComponentBase to bit Boilerplate (#11768) Nov 29, 2025
@ysmoradi ysmoradi merged commit 39c261b into bitfoundation:develop Nov 29, 2025
3 checks passed
@ysmoradi ysmoradi deleted the 11741 branch November 29, 2025 09:19
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.

bit Boilerplate docs for OwnedComponentBase is missing

1 participant