From 9fcc3a123ada4d3f5f39a6dd1c9b6cd5656abc21 Mon Sep 17 00:00:00 2001 From: Richard Forrest Date: Wed, 15 Jul 2020 10:43:05 +0100 Subject: [PATCH] Add details on the correct use of unit of work in event handlers --- docs/en/Distributed-Event-Bus.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/Distributed-Event-Bus.md b/docs/en/Distributed-Event-Bus.md index 947b0f3142..0f2900e988 100644 --- a/docs/en/Distributed-Event-Bus.md +++ b/docs/en/Distributed-Event-Bus.md @@ -178,8 +178,11 @@ That's all. You can inject any service and perform any required logic here. A single event handler class can **subscribe to multiple events** but implementing the `IDistributedEventHandler` interface for each event type. +In your handler if you call a methods on a Repository you may find that you get an `ObjectDisposedException` being thrown. This will be because the unit of work being used by the Repository has been disposed in another context e.g. an ASP.net controller action. You will need to create a specific unit of work for your `HandleEventAsync` method. You can either use the `IUnitOfWorkManager.Begin` method or use the `UnitOfWorkAttribute` on the method. See the [Unit of work document](Unit-of-work.md) for more details. + > The handler class must be registered to the dependency injection (DI). The sample above uses the `ITransientDependency` to accomplish it. See the [DI document](Dependency-Injection.md) for more options. + ## Pre-Defined Events ABP Framework **automatically publishes** distributed events for **create, update and delete** operations for an [entity](Entities.md) once you configure it.