Browse Source

Refactoring Integration Events so they cannot be confused with Domain Events

pull/126/head
Cesar De la Torre 8 years ago
parent
commit
5a374e97b5
7 changed files with 12 additions and 15 deletions
  1. +3
    -3
      src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs
  2. +2
    -2
      src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs
  3. +3
    -3
      src/Services/Basket/Basket.API/Startup.cs
  4. +1
    -1
      src/Services/Catalog/Catalog.API/Catalog.API.csproj
  5. +1
    -1
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
  6. +0
    -3
      src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt
  7. +2
    -2
      src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs

src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedEventHandler.cs → src/Services/Basket/Basket.API/IntegrationEvents/EventHandling/ProductPriceChangedIntegrationEventHandler.cs View File

@ -6,15 +6,15 @@ using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling
{
public class ProductPriceChangedEventHandler : IIntegrationEventHandler<ProductPriceChangedEvent>
public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>
{
private readonly IBasketRepository _repository;
public ProductPriceChangedEventHandler(IBasketRepository repository)
public ProductPriceChangedIntegrationEventHandler(IBasketRepository repository)
{
_repository = repository;
}
public async Task Handle(ProductPriceChangedEvent @event)
public async Task Handle(ProductPriceChangedIntegrationEvent @event)
{
var userIds = await _repository.GetUsers();
foreach (var id in userIds)

src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs → src/Services/Basket/Basket.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs View File

@ -8,7 +8,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class ProductPriceChangedEvent : IntegrationEvent
public class ProductPriceChangedIntegrationEvent : IntegrationEvent
{
public int ProductId { get; private set; }
@ -16,7 +16,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
public decimal OldPrice { get; private set; }
public ProductPriceChangedEvent(int productId, decimal newPrice, decimal oldPrice)
public ProductPriceChangedIntegrationEvent(int productId, decimal newPrice, decimal oldPrice)
{
ProductId = productId;
NewPrice = newPrice;

+ 3
- 3
src/Services/Basket/Basket.API/Startup.cs View File

@ -76,7 +76,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
});
services.AddTransient<IBasketRepository, RedisBasketRepository>();
services.AddTransient<IIntegrationEventHandler<ProductPriceChangedEvent>, ProductPriceChangedEventHandler>();
services.AddTransient<IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>, ProductPriceChangedIntegrationEventHandler>();
var serviceProvider = services.BuildServiceProvider();
var configuration = serviceProvider.GetRequiredService<IOptionsSnapshot<BasketSettings>>().Value;
@ -84,8 +84,8 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddSingleton<IEventBus>(eventBus);
var catalogPriceHandler = serviceProvider.GetService<IIntegrationEventHandler<ProductPriceChangedEvent>>();
eventBus.Subscribe<ProductPriceChangedEvent>(catalogPriceHandler);
var catalogPriceHandler = serviceProvider.GetService<IIntegrationEventHandler<ProductPriceChangedIntegrationEvent>>();
eventBus.Subscribe<ProductPriceChangedIntegrationEvent>(catalogPriceHandler);
}


+ 1
- 1
src/Services/Catalog/Catalog.API/Catalog.API.csproj View File

@ -22,7 +22,7 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Compile Include="IntegrationEvents\EventHandling\AnyFutureIntegrationEventHandler.cs.txt" />
<Compile Include="IntegrationEvents\Events\ProductPriceChangedEvent.cs.txt" />
<Compile Include="IntegrationEvents\Events\ProductPriceChangedIntegrationEvent.cs.txt" />
<Content Update="web.config;">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>


+ 1
- 1
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -146,7 +146,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
item.Price = value.Price;
_context.CatalogItems.Update(item);
var @event = new ProductPriceChangedEvent(item.Id, item.Price, oldPrice);
var @event = new ProductPriceChangedIntegrationEvent(item.Id, item.Price, oldPrice);
var eventLogEntry = new IntegrationEventLogEntry(@event);
_context.IntegrationEventLog.Add(eventLogEntry);


+ 0
- 3
src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs.txt View File

@ -1,3 +0,0 @@

// To implement any future integration event handler here

src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedEvent.cs → src/Services/Catalog/Catalog.API/IntegrationEvents/Events/ProductPriceChangedIntegrationEvent.cs View File

@ -8,7 +8,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
// Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be
// An Integration Event is an event that can cause side effects to other microsrvices, Bounded-Contexts or external systems.
public class ProductPriceChangedEvent : IntegrationEvent
public class ProductPriceChangedIntegrationEvent : IntegrationEvent
{
public int ProductId { get; private set; }
@ -16,7 +16,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
public decimal OldPrice { get; private set; }
public ProductPriceChangedEvent(int productId, decimal newPrice, decimal oldPrice)
public ProductPriceChangedIntegrationEvent(int productId, decimal newPrice, decimal oldPrice)
{
ProductId = productId;
NewPrice = newPrice;

Loading…
Cancel
Save