2

I am trying to use EventBus as described here.

Here is my EventData class

    public class UpdateEntryEventData: EventData
    {
        public long? AttributeId { get; set; }
        public int? TenantId { get; set; }
        public Guid Id { get; set; }
    }

Interface

    public interface IEntryEventManager: IEventHandler<UpdateEntryEventData>, ITransientDependency
    {

    }

The interface implementation

    public class EntryEventManager : DasServiceBase, IEntryEventManager
    {
        public void HandleEvent(UpdateEntryEventData eventData)
        {
            // Some logic when an entry is updated ...
        }
    }

Here is when I call the method to trigger the event.

public class EntryManager : DasDomainServiceBase, IEntryManager
{
   public IEventBus EventBus { get; set; }
   
   public EntryManager()
   {
     EventBus = NullEventBus.Instance;
   }

   public async Task<MessageOutput<Guid>> UpdateAsync(UpdateEntryInput input)
   {
      input.Entry = await _customDataManager.GetEntryAsync(input.Entry, AbpSession?.TenantId);

      var result = await _entryStore.UpdateAsync(input).ConfigureAwait(false);
                        
      EventBus.Trigger(new UpdateEntryEventData
      {
         TenantId = AbpSession.GetTenantId(),
         Id = input.Id,
         AttributeId = input.AttributeId
       });

       return new MessageOutput<Guid>(result, null);
    }   
}

Based on the explation of the tutorial if our class implements: IEventHandler, ITransientDependency it will be registered. But for some reason that I can't figure out now the event is not being triggered.

Flavio Francisco
  • 755
  • 1
  • 8
  • 21

1 Answers1

2

I did some updates on my code and it is working now.

  • DasServiceBase removed
    public class EntryEventManager : IEntryEventManager
    {
        public void HandleEvent(UpdateEntryEventData eventData)
        {
            // Some logic when an entry is updated ...
        }
    }
  • DasDomainServiceBase replaced by DasServiceBase
  • Property EventBus must be public
public class EntryManager : DasServiceBase, IEntryManager
{
   public IEventBus EventBus { get; set; }
}
Flavio Francisco
  • 755
  • 1
  • 8
  • 21