Skip to content

Ensure idempotent dependency registration for MediatorKit#14

Merged
coderynx merged 1 commit into
mainfrom
develop
Mar 20, 2026
Merged

Ensure idempotent dependency registration for MediatorKit#14
coderynx merged 1 commit into
mainfrom
develop

Conversation

@coderynx
Copy link
Copy Markdown
Owner

This pull request updates the dependency injection logic in MediatorKit to prevent duplicate service registrations and avoid overwriting existing registrations for core interfaces like ISender and IPublisher. It replaces AddScoped with TryAddScoped and TryAddEnumerable to ensure that services are only registered if they haven't already been added, improving compatibility and reliability when integrating with other libraries or when configuring services multiple times. The tests have been expanded to verify these behaviors.

Dependency injection improvements:

  • Replaced AddScoped with TryAddScoped for core services (ISender, IPublisher) in DependencyInjection.cs to prevent overwriting existing registrations.
  • Updated registration of pipeline behaviors and handlers to use TryAddEnumerable or TryAddScoped, ensuring duplicate registrations are avoided when adding handlers or behaviors multiple times. [1] [2] [3] [4] [5] [6]

Testing enhancements:

  • Added unit tests to verify that AddMediatorKit does not overwrite existing ISender or IPublisher registrations. [1] [2]
  • Added tests to ensure that request and notification handlers are not registered multiple times when AddMediatorKit is called repeatedly. [1] [2]
  • Introduced custom sender and publisher classes in test files to facilitate these new tests. [1] [2]

Version update:

  • Bumped package version from 1.8.0 to 1.9.0 in version.json.

@coderynx coderynx merged commit a856c23 into main Mar 20, 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.

1 participant