Skip to content

docs: fix dynamic events subscription pattern — use IocEventHandlerFactory instead of raw handler instances#25200

Merged
hikalkan merged 1 commit into
rel-10.3from
maliming/dynamic-events-docs-fix
Apr 2, 2026
Merged

docs: fix dynamic events subscription pattern — use IocEventHandlerFactory instead of raw handler instances#25200
hikalkan merged 1 commit into
rel-10.3from
maliming/dynamic-events-docs-fix

Conversation

@maliming

@maliming maliming commented Apr 2, 2026

Copy link
Copy Markdown
Member

Fix the dynamic events subscription examples to use IocEventHandlerFactory instead of injecting IServiceProvider directly into the handler. The old pattern caused a captive dependency — scoped services resolved from the root container are never properly disposed.

IocEventHandlerFactory is ABP's own mechanism for typed handlers: it creates a new DI scope per event, resolves a fresh handler instance, calls HandleEventAsync, then disposes the scope. The handler can use normal constructor injection without any manual scope management.

Also updated the distributed event bus reference docs and added unit tests verifying scope-per-event creation, DI injection, and handler disposal.

Copilot AI review requested due to automatic review settings April 2, 2026 07:41
@maliming maliming added this to the 10.3-preview milestone Apr 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates ABP documentation and tests to recommend and demonstrate dynamic distributed event subscriptions via IocEventHandlerFactory, avoiding captive-dependency pitfalls and aligning examples with ABP’s typed-handler DI behavior.

Changes:

  • Updated distributed event bus docs to recommend IocEventHandlerFactory for dynamic subscriptions and added a captive-dependency warning for SingleInstanceHandlerFactory.
  • Updated the community article examples to use DI-friendly dynamic handler subscription patterns (factory + constructor injection).
  • Added unit tests to validate IocEventHandlerFactory behavior for dynamic handlers (DI resolution + disposal).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
framework/test/Volo.Abp.EventBus.Tests/Volo/Abp/EventBus/Distributed/LocalDistributedEventBus_Test.cs Adds tests covering DI resolution and disposal behavior when subscribing dynamic handlers via IocEventHandlerFactory.
docs/en/framework/infrastructure/event-bus/distributed/index.md Documents IocEventHandlerFactory as the recommended dynamic subscription approach and warns against captive dependencies with single-instance handlers.
docs/en/Community-Articles/2026-03-23-Dynamic-Events-in-ABP/POST.md Fixes the dynamic subscription pattern to use IocEventHandlerFactory and constructor injection; updates mixed handler example to avoid raw instances.

Comment thread docs/en/Community-Articles/2026-03-23-Dynamic-Events-in-ABP/POST.md
Comment thread docs/en/Community-Articles/2026-03-23-Dynamic-Events-in-ABP/POST.md
@maliming maliming requested a review from hikalkan April 2, 2026 07:46
@hikalkan hikalkan merged commit 9286a66 into rel-10.3 Apr 2, 2026
7 checks passed
@hikalkan hikalkan deleted the maliming/dynamic-events-docs-fix branch April 2, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants