Abp: AddDistributedEvent (Trigger Event)

Created on 20 Dec 2019  路  1Comment  路  Source: abpframework/abp

Hello @hikalkan ,
I have question about trigger event.

In the following example

https://github.com/abpframework/abp/blob/dev/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/Product.cs

You trigger event on line 114

After following example

https://github.com/abpframework/abp/blob/dev/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/ProductManagement/ProductAppService.cs

You updating product on line 74 like below

public async Task UpdateAsync(Guid id, UpdateProductDto input)
{
var product = await _productRepository.GetAsync(id);
pp
product.SetName(input.Name);
product.SetPrice(input.Price);
product.SetStockCount(input.StockCount);
product.SetImageName(input.ImageName);

        return ObjectMapper.Map<Product, ProductDto>(product);
    }

I was wondering if product.SetImageName(input.ImageName); line throw exception, will it still trigger ProductStockCountChangedEto event?

question

Most helpful comment

You trigger event on line 114

We add event on line 114.

https://github.com/abpframework/abp/blob/ac69dc0a0aecbac09874f7a1f9aac8fe49e37a97/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/Product.cs#L114

I was wondering if product.SetImageName(input.ImageName); line throw exception, will it still trigger ProductStockCountChangedEto event?

No, it will not. Distributed events are triggered after SaveChanges/SaveChangesAsync.

https://github.com/abpframework/abp/blob/d16bef05b22ad8ac2c02676dae273852fd86b6f3/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs#L149-L151

>All comments

You trigger event on line 114

We add event on line 114.

https://github.com/abpframework/abp/blob/ac69dc0a0aecbac09874f7a1f9aac8fe49e37a97/samples/MicroserviceDemo/modules/product/src/ProductManagement.Domain/ProductManagement/Product.cs#L114

I was wondering if product.SetImageName(input.ImageName); line throw exception, will it still trigger ProductStockCountChangedEto event?

No, it will not. Distributed events are triggered after SaveChanges/SaveChangesAsync.

https://github.com/abpframework/abp/blob/d16bef05b22ad8ac2c02676dae273852fd86b6f3/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs#L149-L151

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChangYinShung picture ChangYinShung  路  3Comments

hikalkan picture hikalkan  路  3Comments

wocar picture wocar  路  3Comments

leonkosak picture leonkosak  路  3Comments

hikalkan picture hikalkan  路  3Comments