Skip to content

refactor: streamline consumer service retrieval and improve code read… - #36

Merged
mmalkhatib merged 1 commit into
mainfrom
fix/consumer-discovery-dedup
May 17, 2026
Merged

refactor: streamline consumer service retrieval and improve code read…#36
mmalkhatib merged 1 commit into
mainfrom
fix/consumer-discovery-dedup

Conversation

@hamzahalq

@hamzahalq hamzahalq commented May 17, 2026

Copy link
Copy Markdown
Contributor

…ability

Summary by CodeRabbit

  • Bug Fixes
    • Consumer registrations are now deduplicated by type, retaining only the first instance of each consumer type.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

ConsumerDiscovery.Load now deduplicates registered IConsume implementations by grouping them by concrete runtime type and selecting only the first instance per type. The change includes formatting updates to method validation and listener definition construction logic.

Changes

Consumer Deduplication

Layer / File(s) Summary
IConsume deduplication and formatting updates
SW.Bus/ConsumerDiscovery.cs
Load deduplicates IConsume services by grouping all resolved instances by runtime type and selecting the first per type. Method null checks and LoadListeners foreach construction are reformatted for improved readability.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • samerzughul

Poem

🐰 A hop and a skip through the bus so bright,
Duplicates squared? We'll dedupe on sight!
First of each type, we bundle with care,
Consumers now clean, beyond all compare.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately reflects the main change: deduplication of consumer services. It is concise and specific enough for teammates to understand the primary objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/consumer-discovery-dedup

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.

@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 `@SW.Bus/ConsumerDiscovery.cs`:
- Around line 21-23: Remove all references and foreach blocks that call
GetServices<IConsumeGenericBase>() and GetServices<IListenGenericBase>() (these
types don't exist and produce dead code); keep the existing deduplication that
uses scope.ServiceProvider.GetServices<IConsume>().GroupBy(s =>
s.GetType()).Select(g => g.First()) but add a log entry via the available logger
(e.g., processLogger or injected ILogger in ConsumerDiscovery) when GroupBy
produces more than one item for a type to surface duplicate registrations; also
add a short inline comment above the GroupBy...Select explaining that
deduplication is required because Scrutor can register the same class multiple
times (e.g., when scanning IConsumeExtended<T>), so we intentionally pick the
first instance.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 14fe1039-f8c6-4a2a-946f-46452b70c574

📥 Commits

Reviewing files that changed from the base of the PR and between bd28759 and dee9db0.

📒 Files selected for processing (1)
  • SW.Bus/ConsumerDiscovery.cs

Comment thread SW.Bus/ConsumerDiscovery.cs
@mmalkhatib
mmalkhatib merged commit 6966bf3 into main May 17, 2026
2 checks passed
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.

2 participants