Skip to content

feat: Add interceptor registration APIs and assembly scanning#9

Merged
samtrion merged 1 commit intomainfrom
feature/discovery-interceptor-handlers
Jan 11, 2026
Merged

feat: Add interceptor registration APIs and assembly scanning#9
samtrion merged 1 commit intomainfrom
feature/discovery-interceptor-handlers

Conversation

@samtrion
Copy link
Contributor

@samtrion samtrion commented Jan 11, 2026

Introduce extension methods for registering request, command, query, and event interceptors via both explicit and assembly scanning approaches. Includes AOT-safe registration methods and reflection-based scanning with appropriate warnings for Native AOT/IL trimming. Adds comprehensive XML docs and extensive unit tests for all registration scenarios. Enhances support for cross-cutting concerns in the mediator pipeline.

Summary by CodeRabbit

  • New Features

    • Automatic discovery and registration of interceptors from assemblies
    • Manual registration methods for request, command, query, and event interceptors
    • Multiple assembly scanning strategies (by assembly, marker type, calling/entry/executing)
  • Documentation

    • Added usage notes and AOT/IL-trimming caveats for the new scanning APIs
  • Tests

    • Comprehensive unit tests covering scanning, registration lifetimes, chaining, and null checks

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

@samtrion samtrion self-assigned this Jan 11, 2026
@samtrion samtrion requested a review from a team as a code owner January 11, 2026 14:21
@samtrion samtrion requested a review from Hnogared January 11, 2026 14:21
@samtrion samtrion added state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:feature Indicates a new feature or enhancement to be added. labels Jan 11, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

Walkthrough

Adds extension methods to register interceptors both explicitly and via assembly scanning, plus unit tests covering registration, lifetimes, and null checks.

Changes

Cohort / File(s) Summary
Assembly scanning interceptor registration
src/NetEvolve.Pulse/AssemblyScanningExtensions.cs
Adds public methods to scan and register interceptors from assemblies (AddInterceptorsFromAssemblies, AddInterceptorsFromAssembly, AddInterceptorsFromAssemblyContaining<TMarker>, AddInterceptorsFromCallingAssembly, AddInterceptorsFromEntryAssembly, AddInterceptorsFromExecutingAssembly) and an internal RegisterInterceptorsFromAssembly that discovers and registers implementations of IRequestInterceptor<,>, ICommandInterceptor<,>, IQueryInterceptor<,>, IEventInterceptor<> with configurable ServiceLifetime and input validation.
Individual interceptor registration
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs
Adds generic registration helpers: AddRequestInterceptor<...>, AddCommandInterceptor<...>, AddQueryInterceptor<...>, AddEventInterceptor<...> that validate arguments, register service descriptors with specified lifetimes, and include DynamicallyAccessedMembers annotations.
Assembly scanning tests
tests/NetEvolve.Pulse.Tests.Unit/AssemblyScanningExtensionsTests.cs
Adds tests for null-argument behavior, scanning results from assemblies and marker types, lifetime variations, and configurator-return semantics; includes private test interceptor types used for reflection-based discovery.
Handler registration tests
tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs
Adds tests validating null checks, default and explicit lifetimes, multiple registrations/chaining, and correctness of registered ImplementationType and ServiceLifetime for request/command/query/event interceptors.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I hop through code, nose twitching with glee,
I sniff for interceptors in each assembly tree.
Request, Command, Query, Event in a row—
I bind them up neatly, then off I go. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding interceptor registration APIs and assembly scanning capabilities.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization 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 78bba61 and ce29cbb.

📒 Files selected for processing (4)
  • src/NetEvolve.Pulse/AssemblyScanningExtensions.cs
  • src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs
  • tests/NetEvolve.Pulse.Tests.Unit/AssemblyScanningExtensionsTests.cs
  • tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/NetEvolve.Pulse.Tests.Unit/AssemblyScanningExtensionsTests.cs
🧰 Additional context used
🧬 Code graph analysis (3)
src/NetEvolve.Pulse/AssemblyScanningExtensions.cs (3)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (8)
  • IMediatorConfigurator (81-87)
  • IMediatorConfigurator (118-133)
  • IMediatorConfigurator (164-179)
  • IMediatorConfigurator (217-229)
  • IMediatorConfigurator (261-276)
  • IMediatorConfigurator (311-326)
  • IMediatorConfigurator (363-378)
  • IMediatorConfigurator (413-427)
src/NetEvolve.Pulse.Extensibility/IMediatorConfigurator.cs (1)
  • IMediatorConfigurator (143-143)
src/NetEvolve.Pulse/Internals/MediatorConfigurator.cs (1)
  • IMediatorConfigurator (28-40)
tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs (2)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (8)
  • IMediatorConfigurator (81-87)
  • IMediatorConfigurator (118-133)
  • IMediatorConfigurator (164-179)
  • IMediatorConfigurator (217-229)
  • IMediatorConfigurator (261-276)
  • IMediatorConfigurator (311-326)
  • IMediatorConfigurator (363-378)
  • IMediatorConfigurator (413-427)
src/NetEvolve.Pulse/Internals/MediatorConfigurator.cs (1)
  • IMediatorConfigurator (28-40)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (2)
src/NetEvolve.Pulse.Extensibility/IMediatorConfigurator.cs (1)
  • IMediatorConfigurator (143-143)
src/NetEvolve.Pulse/Internals/MediatorConfigurator.cs (1)
  • IMediatorConfigurator (28-40)
⏰ 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 & Tests / Run Tests / Testing .NET solution
🔇 Additional comments (8)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (4)

231-276: LGTM - Interceptor registration follows established patterns.

The implementation correctly mirrors the existing handler registration methods, uses appropriate AOT attributes, and includes comprehensive documentation.


278-326: LGTM - Command interceptor registration is well-implemented.

The method follows the established pattern and includes relevant use cases in the documentation (transaction management, authorization, audit logging).


328-378: LGTM - Query interceptor includes appropriate warnings.

The implementation is correct, and the documentation appropriately warns developers not to modify state in query interceptors, maintaining the side-effect free nature of queries.


380-427: LGTM - Event interceptor correctly handles no-response scenario.

The implementation correctly uses only TEvent and TInterceptor type parameters (no TResponse), which is appropriate for events. The performance warning about keeping interceptors fast and non-blocking is valuable.

tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs (2)

364-658: LGTM - Comprehensive test coverage for all interceptor types.

The tests thoroughly cover all registration scenarios including null checks, default/explicit lifetimes, configurator chaining, and multiple interceptor registration. The test structure is consistent and validates all critical aspects (ServiceType, ImplementationType, Lifetime).


661-686: LGTM - Test interceptor helpers are appropriately minimal.

The test interceptors correctly implement their respective interfaces and simply delegate to the handler, which is perfect for registration testing.

src/NetEvolve.Pulse/AssemblyScanningExtensions.cs (2)

433-726: LGTM - Interceptor scanning methods mirror handler scanning patterns.

The six assembly scanning methods for interceptors correctly follow the same patterns as the existing handler scanning methods. They include proper null validation, AOT warning attributes, and comprehensive documentation.


728-769: LGTM - Interceptor discovery implementation is correct.

The RegisterInterceptorsFromAssembly method correctly discovers and registers interceptors using reflection. It properly filters for non-abstract, non-open-generic classes and registers each discovered interceptor interface implementation. The use of Services.Add() allows multiple registrations for LIFO execution order, which is correct for interceptors.


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.

@codecov
Copy link

codecov bot commented Jan 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.64%. Comparing base (f074839) to head (ce29cbb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #9      +/-   ##
==========================================
+ Coverage   97.18%   97.64%   +0.45%     
==========================================
  Files          10       10              
  Lines         249      297      +48     
  Branches       24       31       +7     
==========================================
+ Hits          242      290      +48     
  Misses          3        3              
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samtrion
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Introduce extension methods for registering request, command, query, and event interceptors via both explicit and assembly scanning approaches. Includes AOT-safe registration methods and reflection-based scanning with appropriate warnings for Native AOT/IL trimming. Adds comprehensive XML docs and extensive unit tests for all registration scenarios. Enhances support for cross-cutting concerns in the mediator pipeline.
@samtrion samtrion force-pushed the feature/discovery-interceptor-handlers branch from 78bba61 to ce29cbb Compare January 11, 2026 19:59
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/NetEvolve.Pulse/AssemblyScanningExtensions.cs (1)

51-52: Fix the syntax error preventing compilation.

Lines 51-52 contain invalid C# syntax:

extension(IMediatorConfigurator configurator)
{

This is not valid C# and will cause a compilation error. These lines should be removed entirely, as all the methods below (starting at line 96) are already properly declared as public static extension methods with this IMediatorConfigurator configurator parameters.

🔧 Proposed fix
 public static class AssemblyScanningExtensions
 {
-    extension(IMediatorConfigurator configurator)
-    {
     /// <summary>
     /// Scans the specified assemblies for handler implementations and registers them.
📜 Review details

Configuration used: Organization 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 78bba61 and ce29cbb.

📒 Files selected for processing (4)
  • src/NetEvolve.Pulse/AssemblyScanningExtensions.cs
  • src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs
  • tests/NetEvolve.Pulse.Tests.Unit/AssemblyScanningExtensionsTests.cs
  • tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/NetEvolve.Pulse.Tests.Unit/AssemblyScanningExtensionsTests.cs
🧰 Additional context used
🧬 Code graph analysis (3)
src/NetEvolve.Pulse/AssemblyScanningExtensions.cs (3)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (8)
  • IMediatorConfigurator (81-87)
  • IMediatorConfigurator (118-133)
  • IMediatorConfigurator (164-179)
  • IMediatorConfigurator (217-229)
  • IMediatorConfigurator (261-276)
  • IMediatorConfigurator (311-326)
  • IMediatorConfigurator (363-378)
  • IMediatorConfigurator (413-427)
src/NetEvolve.Pulse.Extensibility/IMediatorConfigurator.cs (1)
  • IMediatorConfigurator (143-143)
src/NetEvolve.Pulse/Internals/MediatorConfigurator.cs (1)
  • IMediatorConfigurator (28-40)
tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs (2)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (8)
  • IMediatorConfigurator (81-87)
  • IMediatorConfigurator (118-133)
  • IMediatorConfigurator (164-179)
  • IMediatorConfigurator (217-229)
  • IMediatorConfigurator (261-276)
  • IMediatorConfigurator (311-326)
  • IMediatorConfigurator (363-378)
  • IMediatorConfigurator (413-427)
src/NetEvolve.Pulse/Internals/MediatorConfigurator.cs (1)
  • IMediatorConfigurator (28-40)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (2)
src/NetEvolve.Pulse.Extensibility/IMediatorConfigurator.cs (1)
  • IMediatorConfigurator (143-143)
src/NetEvolve.Pulse/Internals/MediatorConfigurator.cs (1)
  • IMediatorConfigurator (28-40)
⏰ 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 & Tests / Run Tests / Testing .NET solution
🔇 Additional comments (8)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (4)

231-276: LGTM - Interceptor registration follows established patterns.

The implementation correctly mirrors the existing handler registration methods, uses appropriate AOT attributes, and includes comprehensive documentation.


278-326: LGTM - Command interceptor registration is well-implemented.

The method follows the established pattern and includes relevant use cases in the documentation (transaction management, authorization, audit logging).


328-378: LGTM - Query interceptor includes appropriate warnings.

The implementation is correct, and the documentation appropriately warns developers not to modify state in query interceptors, maintaining the side-effect free nature of queries.


380-427: LGTM - Event interceptor correctly handles no-response scenario.

The implementation correctly uses only TEvent and TInterceptor type parameters (no TResponse), which is appropriate for events. The performance warning about keeping interceptors fast and non-blocking is valuable.

tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs (2)

364-658: LGTM - Comprehensive test coverage for all interceptor types.

The tests thoroughly cover all registration scenarios including null checks, default/explicit lifetimes, configurator chaining, and multiple interceptor registration. The test structure is consistent and validates all critical aspects (ServiceType, ImplementationType, Lifetime).


661-686: LGTM - Test interceptor helpers are appropriately minimal.

The test interceptors correctly implement their respective interfaces and simply delegate to the handler, which is perfect for registration testing.

src/NetEvolve.Pulse/AssemblyScanningExtensions.cs (2)

433-726: LGTM - Interceptor scanning methods mirror handler scanning patterns.

The six assembly scanning methods for interceptors correctly follow the same patterns as the existing handler scanning methods. They include proper null validation, AOT warning attributes, and comprehensive documentation.


728-769: LGTM - Interceptor discovery implementation is correct.

The RegisterInterceptorsFromAssembly method correctly discovers and registers interceptors using reflection. It properly filters for non-abstract, non-open-generic classes and registers each discovered interceptor interface implementation. The use of Services.Add() allows multiple registrations for LIFO execution order, which is correct for interceptors.

@samtrion samtrion merged commit e20a248 into main Jan 11, 2026
9 checks passed
@samtrion samtrion deleted the feature/discovery-interceptor-handlers branch January 11, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:ready for merge Indicates that a pull request has been reviewed and approved, and is ready to be merged into the mai type:feature Indicates a new feature or enhancement to be added.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant