feat: Add interceptor registration APIs and assembly scanning#9
feat: Add interceptor registration APIs and assembly scanning#9
Conversation
WalkthroughAdds extension methods to register interceptors both explicitly and via assembly scanning, plus unit tests covering registration, lifetimes, and null checks. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro Knowledge base: Disabled due to 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code graph analysis (3)src/NetEvolve.Pulse/AssemblyScanningExtensions.cs (3)
tests/NetEvolve.Pulse.Tests.Unit/HandlerRegistrationExtensionsTests.cs (2)
src/NetEvolve.Pulse/HandlerRegistrationExtensions.cs (2)
⏰ 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)
🔇 Additional comments (8)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
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.
78bba61 to
ce29cbb
Compare
There was a problem hiding this comment.
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 staticextension methods withthis IMediatorConfigurator configuratorparameters.🔧 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
📒 Files selected for processing (4)
src/NetEvolve.Pulse/AssemblyScanningExtensions.cssrc/NetEvolve.Pulse/HandlerRegistrationExtensions.cstests/NetEvolve.Pulse.Tests.Unit/AssemblyScanningExtensionsTests.cstests/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
TEventandTInterceptortype parameters (noTResponse), 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
RegisterInterceptorsFromAssemblymethod 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 ofServices.Add()allows multiple registrations for LIFO execution order, which is correct for interceptors.
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
Documentation
Tests
✏️ Tip: You can customize this high-level summary in your review settings.