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.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38