Add a way to skip a handler in the pipeline#185
Merged
Merged
Conversation
When building the pipeline, sometimes it's useful for Use(...) to conditionally turn themselves off depending on some service or configuration. Rather than inject a passthrough DelegatingHandler needlessly, this allows these cases to return a WhatsAppHandler.Skip instead, which will not be added to the pipeline at all
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for conditionally skipping handlers in the WhatsApp pipeline by returning a dedicated Skip handler.
- Refactors the handler invocations in the pipeline builder to check for Skip.
- Introduces a Skip handler type in WhatsAppHandler and updates the pipeline test accordingly.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/WhatsApp/WhatsAppHandlerBuilder.cs | Updates the pipeline builder to conditionally apply factories. |
| src/WhatsApp/WhatsAppHandler.cs | Adds a new Skip handler and updates related documentation. |
| src/Tests/PipelineTests.cs | Modifies tests to include the new Skip handler logic. |
Comments suppressed due to low confidence (1)
src/WhatsApp/WhatsAppHandler.cs:20
- [nitpick] The class name 'SKipWhatsAppHandler' contains a typo with inconsistent capitalization. Consider renaming it to 'SkipWhatsAppHandler' for clarity and consistency.
public static IWhatsAppHandler Skip { get; } = new SKipWhatsAppHandler();
|
|
||
| // Only keep non-skipping handlers. | ||
| if (current != WhatsAppHandler.Skip) | ||
| handler = factories[i](handler!, services); |
There was a problem hiding this comment.
The factory method is invoked twice for the same index. Instead, consider assigning 'handler = current' when the current handler is not Skip to avoid potential side effects from the second invocation.
Suggested change
| handler = factories[i](handler!, services); | |
| handler = current; |
Member
Author
🧪 Details on Ubuntu 24.04.2 LTSfrom dotnet-retest v0.7.1 on .NET 8.0.17 with 💜 by @devlooped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When building the pipeline, sometimes it's useful for Use(...) to conditionally turn themselves off depending on some service or configuration. Rather than inject a passthrough DelegatingHandler needlessly, this allows these cases to return a WhatsAppHandler.Skip instead, which will not be added to the pipeline at all