Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped lifetime dependency not working on class implementing ILocalEventHandler #21517

Open
1 task done
martinkraan opened this issue Dec 2, 2024 · 3 comments
Open
1 task done

Comments

@martinkraan
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Description

When creating a handler for a localevent implementing the interface ILocalEventHandler and registering the handler for DI, only transient and singleton work as expected, scoped lifetime does not.

Reproduction Steps

using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus;

namespace AbpDemo
{
    public class MyHandler()
        : ILocalEventHandler<StockCountChangedEvent>,
          IScopedDependency
    {
        public async Task HandleEventAsync(StockCountChangedEvent eventData)
        {
             // When multiple events occur in the same request we get a new instance of MyHandler for every event handled here
        }
    }
}

Expected behavior

Expected behaviour is that the lifetime scope of the request is applied to the eventhandler.

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

8.2.0

User Interface

Common (Default)

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

@martinkraan martinkraan added the bug label Dec 2, 2024
@maliming maliming self-assigned this Dec 2, 2024
@maliming
Copy link
Member

maliming commented Dec 3, 2024

hi

It is not supported IScopedDependency currently.

The Handler class is not be activated in an HTTP request.
for example, the RabbitMQ is used to subscribe to the message and process the event.

@maliming maliming removed the bug label Dec 3, 2024
@maliming maliming removed their assignment Dec 3, 2024
@martinkraan
Copy link
Author

Hi,

that's unfortunate it is not supported.

You state that the Handler class is not to be activated in a HTTP Request, but I would assume that the local events (Domain Events) published in the aggregateroot or entity that are processed by the ABP framework when the changes are saved to the database are executed in the same scope and not in a new scope! The local events are handled inside the UoW so I would think that they should also be in the same scope.

@maliming
Copy link
Member

maliming commented Dec 3, 2024

hi

If you have two local events, the execution order will be one by one.

So we can't get all events, create a scope, and execute them in the same scope.

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

No branches or pull requests

2 participants