Refactoring Integration Events so they cannot be confused with Domain Events
This commit is contained in:
parent
b9c1778d9d
commit
5a374e97b5
@ -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)
|
@ -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;
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
|
||||
|
||||
// To implement any future integration event handler here
|
@ -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…
x
Reference in New Issue
Block a user