Skip to content

Generate concrete behavior registrations - #392

Merged
viceroypenguin merged 2 commits into
mainfrom
behaviors
Aug 7, 2026
Merged

Generate concrete behavior registrations#392
viceroypenguin merged 2 commits into
mainfrom
behaviors

Conversation

@viceroypenguin

@viceroypenguin viceroypenguin commented Aug 7, 2026

Copy link
Copy Markdown
Member

Fixes #390

Summary by CodeRabbit

  • New Features

    • AddXxxHandlers() now automatically registers associated behaviors.
    • Handler and behavior registrations preserve configured service lifetimes and avoid duplicate entries.
    • Streaming and non-streaming handlers receive consistent dependency-injection registration.
  • Breaking Changes

    • Separate AddXxxBehaviors() registration methods are no longer generated or required.
    • Updated samples and documentation reflect the streamlined registration process.
  • Tests

    • Added coverage for handler, streaming handler, and behavior registration scenarios.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6fe7934f-b2e9-4d1e-8a82-3894d5363fa8

📥 Commits

Reviewing files that changed from the base of the PR and between 1342693 and c897f01.

📒 Files selected for processing (1)
  • tests/Immediate.Handlers.FunctionalTests/RegistrationTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Immediate.Handlers.FunctionalTests/RegistrationTests.cs

📝 Walkthrough

Walkthrough

The generator now registers behavior dependencies through AddXxxHandlers(). Handler, behavior, interface, and container registrations use conditional service descriptors. Separate behavior registration methods and calls were removed. Tests and snapshots cover idempotent registrations across handler types and frameworks.

Changes

Unified handler registration

Layer / File(s) Summary
Generator registration model
src/Immediate.Handlers.Generators/ImmediateHandlersGenerator.cs, src/Immediate.Handlers.Generators/Models.cs, src/Immediate.Handlers.Generators/TransformBehaviors.cs
Removed global behavior registration data and simplified behavior type-name generation.
Generated dependency injection registration
src/Immediate.Handlers.Generators/Templates/Handler.sbntxt
AddHandlers registers behavior dependencies and uses TryAdd with described service descriptors for handlers, interfaces, behaviors, and containers.
Integration and registration validation
tests/Immediate.Handlers.FunctionalTests/*
Removed separate behavior registration from test setup and added repeated-registration coverage for regular and streaming handlers.
Concrete generated registration coverage
tests/Immediate.Handlers.Tests/GeneratorTests/AddHandlersTests.cs, tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.*
Added coverage for concrete behavior registrations and generated handler extensions across supported frameworks.
Registration regression snapshots
tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.*, tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.*, tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/StreamingHandlerTests.*
Updated generated snapshots to verify conditional registrations, preserved lifetimes, behavior dependencies, and streaming handler mappings.
Usage and output expectations
readme.md, samples/Normal/Program.cs, .gitattributes, tests/Immediate.Handlers.Tests/GeneratorTests/Invalid*Tests.cs
Updated usage instructions, sample registration, generated output expectations, and verified snapshot encoding rules.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: generating concrete behavior registrations.
Linked Issues check ✅ Passed The changes generate concrete behavior registrations and preserve handler, streaming handler, and behavior registration paths required by issue #390.
Out of Scope Changes check ✅ Passed The code, documentation, configuration, and snapshot updates support concrete behavior registration and its tests without unrelated changes.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch behaviors

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/Immediate.Handlers.FunctionalTests/RegistrationTests.cs`:
- Line 14: Update the registration test to invoke both
MultipleBehaviorHandler.AddHandlers and
MultipleStreamingBehaviorsHandler.AddHandlers twice before the assertions. Keep
the existing expected descriptor lists unchanged so the test verifies duplicate
registration is handled correctly.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 69530036-7b28-4727-921d-931abcfaae2c

📥 Commits

Reviewing files that changed from the base of the PR and between f11a403 and 1342693.

📒 Files selected for processing (70)
  • .gitattributes
  • readme.md
  • samples/Normal/Program.cs
  • src/Immediate.Handlers.Generators/ImmediateHandlersGenerator.cs
  • src/Immediate.Handlers.Generators/Models.cs
  • src/Immediate.Handlers.Generators/Templates/Handler.sbntxt
  • src/Immediate.Handlers.Generators/Templates/ServiceCollectionExtensions.sbntxt
  • src/Immediate.Handlers.Generators/TransformBehaviors.cs
  • tests/Immediate.Handlers.FunctionalTests/HandlerResolver.cs
  • tests/Immediate.Handlers.FunctionalTests/RegistrationTests.cs
  • tests/Immediate.Handlers.FunctionalTests/Tags/TaggedRegistrationTests.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/AddHandlersTests.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/HandlerTests.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/InvalidBehaviorsTests.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/InvalidHandlerTests.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net10.0#IH..FirstHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net10.0#IH..SecondHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net10.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net11.0#IH..FirstHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net11.0#IH..SecondHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net11.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net8.0#IH..FirstHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net8.0#IH..SecondHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net8.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net9.0#IH..FirstHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net9.0#IH..SecondHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.BehaviorsUseConcreteRegistrations_framework=net9.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.ValidAddHandlersMethod_framework=net10.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.ValidAddHandlersMethod_framework=net11.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.ValidAddHandlersMethod_framework=net8.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/AddHandlersTests.ValidAddHandlersMethod_framework=net9.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.BehaviorHasMultipleTRequestConstraints#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.BehaviorHasMultipleTResponseConstraints#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.CrtpBehavior#IH..ConstraintHandler.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.MultipleBehaviors#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.NestedBehavior#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.NullableBehavior_behaviorNullable=False_returnNullable=False#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.NullableBehavior_behaviorNullable=False_returnNullable=True#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.NullableBehavior_behaviorNullable=True_returnNullable=False#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.NullableBehavior_behaviorNullable=True_returnNullable=True#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.RequestTypeParameterBehavior#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.ResponseTypeParameterBehavior#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.SingleBehavior#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/BehaviorTests.ZeroTypeParameterBehavior#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.ComplexParameterAttribute#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.HandlerTags#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.IntReturnType_modifier=#IH.Dummy.GetUsersQuery.g.verified.cs``
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.IntReturnType_modifier=static#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.MissingCancellationToken_modifier=#IH.Dummy.GetUsersQuery.g.verified.cs``
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.MissingCancellationToken_modifier=static#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.MultipleParameterAttributes#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.NullableParameterType#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.NullableReturnType#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.ServiceLifetime_lifetime=Scoped#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.ServiceLifetime_lifetime=Singleton#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.ServiceLifetime_lifetime=Transient#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.SimpleParameterAttribute#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.VoidReturnType_modifier=#IH.Dummy.GetUsersQuery.g.verified.cs``
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/HandlerTests.VoidReturnType_modifier=static#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net10.0#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net10.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net11.0#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net11.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net8.0#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net8.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net9.0#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net9.0#IH.ServiceCollectionExtensions.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/StreamingHandlerTests.StreamingBehavior#IH.Dummy.GetUsersQuery.g.verified.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/StreamingHandlerTests.StreamingIntReturnType_modifier=#IH.Dummy.GetUsersQuery.g.verified.cs``
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/StreamingHandlerTests.StreamingIntReturnType_modifier=static#IH.Dummy.GetUsersQuery.g.verified.cs
💤 Files with no reviewable changes (8)
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net9.0#IH.ServiceCollectionExtensions.g.verified.cs
  • src/Immediate.Handlers.Generators/TransformBehaviors.cs
  • src/Immediate.Handlers.Generators/Models.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net10.0#IH.ServiceCollectionExtensions.g.verified.cs
  • src/Immediate.Handlers.Generators/Templates/ServiceCollectionExtensions.sbntxt
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net8.0#IH.ServiceCollectionExtensions.g.verified.cs
  • samples/Normal/Program.cs
  • tests/Immediate.Handlers.Tests/GeneratorTests/Snapshots/ImmediateAssemblyIdentifierTests.ImmediateAssemblyIdentifierOverridesAssemblyName_framework=net11.0#IH.ServiceCollectionExtensions.g.verified.cs

Comment thread tests/Immediate.Handlers.FunctionalTests/RegistrationTests.cs
@coveralls

coveralls commented Aug 7, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 31143653186

Coverage decreased (-0.06%) to 93.829%

Details

  • Coverage decreased (-0.06%) from the base build.
  • Patch coverage: 9 of 9 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1588
Covered Lines: 1490
Line Coverage: 93.83%
Coverage Strength: 3.75 hits per line

💛 - Coveralls

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.

System.InvalidOperationException during ServiceStart when <PublishAot>true</PublishAot> is supplied in csproj file

2 participants