From cb4da9864d2a38c1fdd35abba1600b75c5a54075 Mon Sep 17 00:00:00 2001 From: Cesar De la Torre Date: Tue, 21 Mar 2017 12:55:33 -0700 Subject: [PATCH 1/3] Dispatching Domain Events right before DbContext SaveChanges() so side effects from additional Domain Event Handlers are included within the same transaction --- .../Ordering.Infrastructure/OrderingContext.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs index de3f870da..d28b4e3f9 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs @@ -237,10 +237,18 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure public async Task SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken)) { + // Dispatch Domain Events collection. + // Choices: + // A) Right BEFORE committing data (EF SaveChanges) into the DB will make a single transaction including + // side effects from the domain event handlers which are using the same DbContext with "InstancePerLifetimeScope" or "scoped" lifetime + // B) Right AFTER committing data (EF SaveChanges) into the DB. will make multiple transactions. + // You will need to handle eventual consistency and compensatory actions in case of failures. + await _mediator.DispatchDomainEventsAsync(this); + + + // After executing this line all the changes performed thought the DbContext will be commited var result = await base.SaveChangesAsync(); - // Dispatch the Domain Events collection right after saving/committing data into the database - await _mediator.DispatchDomainEventsAsync(this); return result; } } From bb39e5fd6eda370937f7c7ce05e94e544ab0dcfb Mon Sep 17 00:00:00 2001 From: Cesar De la Torre Date: Tue, 21 Mar 2017 12:58:07 -0700 Subject: [PATCH 2/3] Minor comment change --- .../Ordering/Ordering.Infrastructure/OrderingContext.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs index d28b4e3f9..b74c7631d 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs @@ -241,8 +241,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure // Choices: // A) Right BEFORE committing data (EF SaveChanges) into the DB will make a single transaction including // side effects from the domain event handlers which are using the same DbContext with "InstancePerLifetimeScope" or "scoped" lifetime - // B) Right AFTER committing data (EF SaveChanges) into the DB. will make multiple transactions. - // You will need to handle eventual consistency and compensatory actions in case of failures. + // B) Right AFTER committing data (EF SaveChanges) into the DB will make multiple transactions. + // You will need to handle eventual consistency and compensatory actions in case of failures in any of the Handlers. await _mediator.DispatchDomainEventsAsync(this); From 696610ed3636fd66584ed4ad12d14cdf3dbe693c Mon Sep 17 00:00:00 2001 From: dsanz Date: Wed, 22 Mar 2017 09:57:08 +0100 Subject: [PATCH 3/3] Fix #129 Post_update_product_price_and_catalog_and_basket_list_modified test failing --- .../Catalog/Catalog.API/Controllers/CatalogController.cs | 3 +++ .../FunctionalTests/Services/Catalog/CatalogScenariosBase.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index 4add23b35..b60ddc27c 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -130,6 +130,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers return Ok(items); } + //POST api/v1/[controller]/edit [Route("edit")] [HttpPost] public async Task EditProduct([FromBody]CatalogItem product) @@ -164,6 +165,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers return Ok(); } + //POST api/v1/[controller]/create [Route("create")] [HttpPost] public async Task CreateProduct([FromBody]CatalogItem product) @@ -184,6 +186,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers return Ok(); } + //DELETE api/v1/[controller]/id [Route("{id}")] [HttpDelete] public async Task DeleteProduct(int id) diff --git a/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs b/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs index 727e58a00..f7a847934 100644 --- a/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs +++ b/test/Services/FunctionalTests/Services/Catalog/CatalogScenariosBase.cs @@ -34,7 +34,7 @@ namespace FunctionalTests.Services.Catalog public static class Post { - public static string UpdateCatalogProduct = "api/v1/catalog"; + public static string UpdateCatalogProduct = "api/v1/catalog/edit"; } } }