Refactoring Integration Events so they cannot be confused with Domain Events

This commit is contained in:
Cesar De la Torre 2017-03-16 18:59:20 -07:00
parent b9c1778d9d
commit 5a374e97b5
7 changed files with 12 additions and 15 deletions

View File

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

View File

@ -8,7 +8,7 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Even
// Integration Events notes: // Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be // 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. // 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; } 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 decimal OldPrice { get; private set; }
public ProductPriceChangedEvent(int productId, decimal newPrice, decimal oldPrice) public ProductPriceChangedIntegrationEvent(int productId, decimal newPrice, decimal oldPrice)
{ {
ProductId = productId; ProductId = productId;
NewPrice = newPrice; NewPrice = newPrice;

View File

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

View File

@ -22,7 +22,7 @@
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content> </Content>
<Compile Include="IntegrationEvents\EventHandling\AnyFutureIntegrationEventHandler.cs.txt" /> <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;"> <Content Update="web.config;">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content> </Content>

View File

@ -146,7 +146,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
item.Price = value.Price; item.Price = value.Price;
_context.CatalogItems.Update(item); _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); var eventLogEntry = new IntegrationEventLogEntry(@event);
_context.IntegrationEventLog.Add(eventLogEntry); _context.IntegrationEventLog.Add(eventLogEntry);

View File

@ -1,3 +0,0 @@

// To implement any future integration event handler here

View File

@ -8,7 +8,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.IntegrationEvents.Eve
// Integration Events notes: // Integration Events notes:
// An Event is “something that has happened in the past”, therefore its name has to be // 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. // 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; } 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 decimal OldPrice { get; private set; }
public ProductPriceChangedEvent(int productId, decimal newPrice, decimal oldPrice) public ProductPriceChangedIntegrationEvent(int productId, decimal newPrice, decimal oldPrice)
{ {
ProductId = productId; ProductId = productId;
NewPrice = newPrice; NewPrice = newPrice;