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
|
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)
|
@ -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;
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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>
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
@ -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:
|
// 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;
|
Loading…
x
Reference in New Issue
Block a user