abp icon indicating copy to clipboard operation
abp copied to clipboard

Define ETO's for all aggregate roots for all modules

Open hikalkan opened this issue 6 years ago • 4 comments

ETO: Event Transfer Object.

Used to transfer info about a change for an entity, like creation, deletion and updating.

If we don't define a specific ETO for an entity, the default one is used, which simply has entity name and id.

Defining specific ETO allows to easily subscribe to an event of that entity type. There are 3 steps to define an ETO for an aggregate root:

  1. Create a ETO class that contains the ensential properties of the agg.root, in the .Domain.Shared project. Example:

https://github.com/abpframework/abp/blob/ecac0358fbc9a0acbbda91111d41d5ee6bfb795a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain.Shared/Volo/Abp/TenantManagement/TenantEto.cs#L1-L12

  1. Register it for Entity to ETO mapping, in the .Domain project. Example:

https://github.com/abpframework/abp/blob/ecac0358fbc9a0acbbda91111d41d5ee6bfb795a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainModule.cs#L29-L32

  1. Define the AutoMapper mapping (which is used for the mapping by default) in the .Domain project. Example:

https://github.com/abpframework/abp/blob/ecac0358fbc9a0acbbda91111d41d5ee6bfb795a/modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/AbpTenantManagementDomainMappingProfile.cs#L27

That's all. Then ABP will automatically publish create,delete,update events for this ETO when corresponding entity change happen. You can subsrcibe the event you like, example:

https://github.com/abpframework/abp/blob/ecac0358fbc9a0acbbda91111d41d5ee6bfb795a/samples/MicroserviceDemo/microservices/IdentityService.Host/Tenants/TenantCreatedDistributedEventHandler.cs#L13-L37

Notice that this is a distributed event, but will be in-process by default. When you configure RabbitMq or another real distributed event bus provider, it will be real distributed.

hikalkan avatar Mar 09 '20 16:03 hikalkan

Update https://github.com/abpframework/abp/blob/dev/docs/en/Customizing-Application-Modules-Guide.md#subscribing-to-distributed-events once this issue is done!

hikalkan avatar Mar 11 '20 13:03 hikalkan

  • [x] Identity
  • [x] Blogging
  • [x] Docs
  • [x] IdentityServer

cotur avatar Mar 19 '20 10:03 cotur

...related official doc should be updated: https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities#subscribing-to-distributed-events

Pre-built application modules do not define specialized event types yet (like UserEto - "ETO" means "Event Transfer Object"). This feature is on the road map and will be available in a short term (follow this issue). Once it is implemented, you will be able to subscribe to individual entity types

sanghel-payoff avatar Jan 13 '22 16:01 sanghel-payoff

Thank you @sanghel-payoff ,

We will update documentation soon. Tracked here: https://github.com/abpframework/abp/issues/11337

cotur avatar Jan 17 '22 11:01 cotur