Open Closed

Subscribe to entity event of specific interface that inherits it. #4418


User avatar
0
jeffbuot created
  • ABP Framework version: 6.0.2

  • DB provider: EF Core
    I have an interface with an entity:

public interface IReferenceObject{
    string ReferenceId {get;}
}

public class Book : FullAuditedAggregateRoot<Guid>, IReferenceObject{
    public Book(Guid id, string referenceId){
        Id = id;
        ReferenceId = referenceId;
    }    
    public string ReferenceId { get; }    
    public string Title { get; set; }
}

My goal is to subscribe on create event to every entities that inherits the IReferenceObject.
I read the documentation here https://docs.abp.io/en/abp/latest/Local-Event-Bus#pre-built-events and tried this:

public class ReferenceObjectEventHandler : ILocalEventHandler<EntityCreatedEventData<IReferenceObject>>, ITransientDependency

{
    public async Task HandleEventAsync(EntityCreatedEventData<IReferenceObject> eventData)
    {
        Console.WriteLine($"Created an entity with reference id {eventData.Entity.ReferenceId}");
    }
}

But it's not working..any suggestion?


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The EntityCreatedEventData only works for an entity.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 19, 2025, 10:09