#实体定义
public class ProductEntity : Entity<Guid>
{
public string Name { get; set; }
}
#ETO定义
public class ProductEto : EntityEto
{
public Guid Id { get; set; }
public string Name { get; set; }
}
#事件注册及ETO映射配置
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpDistributedEntityEventOptions>(options =>
{
//Enable
options.AutoEventSelectors.Add<ProductEntity>();
//Mapping
options.EtoMappings.Add<ProductEntity, ProductEto>();
});
}
#注入事件处理器
public class ProductChangeEventHandler :
IDistributedEventHandler<EntityCreatedEto<ProductEto>>,
IDistributedEventHandler<EntityUpdatedEto<ProductEto>>,
IDistributedEventHandler<EntityDeletedEto<ProductEto>>,
ITransientDependency
{
public Task HandleEventAsync(EntityCreatedEto<ProductEto> eventData)
{
var productId = eventData.Entity.Id;
//TODO
}
public Task HandleEventAsync(EntityUpdatedEto<ProductEto> eventData)
{
var productId = eventData.Entity.Id;
//TODO
}
public Task HandleEventAsync(EntityDeletedEto<ProductEto> eventData)
{
var productId = eventData.Entity.Id;
//TODO
}
}