打开 关闭

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


User avatar
0
jeffbuot 创建
  • 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 答案
  • User Avatar
    0
    maliming 创建
    支持团队 Fullstack Developer

    hi

    The EntityCreatedEventData only works for an entity.

Made with ❤️ on ABP v8.2.0-preview Updated on 三月 25, 2024, 15:11