Remove PaymentIntegrationEventService and remove integration command to integration event
This commit is contained in:
parent
def828aeda
commit
a84c180e07
@ -1,27 +0,0 @@
|
||||
namespace Payment.API.IntegrationCommands.CommandHandlers
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Payment.API.IntegrationCommands.Commands;
|
||||
using System.Threading.Tasks;
|
||||
using Payment.API.IntegrationEvents;
|
||||
using Payment.API.IntegrationEvents.Events;
|
||||
|
||||
public class PayOrderCommandHandler : IIntegrationEventHandler<PayOrderCommand>
|
||||
{
|
||||
private readonly IPaymentIntegrationEventService _paymentIntegrationEventService;
|
||||
|
||||
public PayOrderCommandHandler(IPaymentIntegrationEventService paymentIntegrationEventService)
|
||||
=> _paymentIntegrationEventService = paymentIntegrationEventService;
|
||||
|
||||
public async Task Handle(PayOrderCommand @event)
|
||||
{
|
||||
//PAYMENT SUCCESSED
|
||||
var orderPaymentSuccededIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
|
||||
_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentSuccededIntegrationEvent);
|
||||
|
||||
//PAYMENT FAILED
|
||||
//var orderPaymentFailedIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
|
||||
//_paymentIntegrationEventService.PublishThroughEventBus(orderPaymentFailedIntegrationEvent);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
namespace Payment.API.IntegrationCommands.Commands
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
|
||||
public class PayOrderCommand : IntegrationEvent
|
||||
{
|
||||
public int OrderId { get; }
|
||||
|
||||
public PayOrderCommand(int orderId) => OrderId = orderId;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
namespace Payment.API.IntegrationEvents.EventHandling
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using System.Threading.Tasks;
|
||||
using Payment.API.IntegrationEvents.Events;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
|
||||
public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
|
||||
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>
|
||||
{
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly PaymentSettings _settings;
|
||||
|
||||
public OrderStatusChangedToStockConfirmedIntegrationEventHandler(IEventBus eventBus,
|
||||
IOptionsSnapshot<PaymentSettings> settings)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_settings = settings.Value;
|
||||
}
|
||||
|
||||
public async Task Handle(OrderStatusChangedToStockConfirmedIntegrationEvent @event)
|
||||
{
|
||||
IntegrationEvent orderPaymentIntegrationEvent;
|
||||
if(_settings.SuccessPayment)
|
||||
{
|
||||
orderPaymentIntegrationEvent = new OrderPaymentSuccededIntegrationEvent(@event.OrderId);
|
||||
}
|
||||
else
|
||||
{
|
||||
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
|
||||
}
|
||||
|
||||
_eventBus.Publish(orderPaymentIntegrationEvent);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
namespace Payment.API.IntegrationEvents.Events
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
|
||||
public class OrderStatusChangedToStockConfirmedIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
public int OrderId { get; }
|
||||
|
||||
public OrderStatusChangedToStockConfirmedIntegrationEvent(int orderId)
|
||||
=> OrderId = orderId;
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
namespace Payment.API.IntegrationEvents
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
|
||||
public interface IPaymentIntegrationEventService
|
||||
{
|
||||
void PublishThroughEventBus(IntegrationEvent evt);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
namespace Payment.API.IntegrationEvents
|
||||
{
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
|
||||
using System;
|
||||
|
||||
public class PaymentIntegrationEventService : IPaymentIntegrationEventService
|
||||
{
|
||||
private readonly IEventBus _eventBus;
|
||||
|
||||
public PaymentIntegrationEventService(IEventBus eventBus)
|
||||
{
|
||||
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
|
||||
}
|
||||
|
||||
public void PublishThroughEventBus(IntegrationEvent evt)
|
||||
{
|
||||
_eventBus.Publish(evt); ;
|
||||
}
|
||||
}
|
||||
}
|
8
src/Services/Payment/Payment.API/PaymentSettings.cs
Normal file
8
src/Services/Payment/Payment.API/PaymentSettings.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace Payment.API
|
||||
{
|
||||
public class PaymentSettings
|
||||
{
|
||||
public bool SuccessPayment { get; set; }
|
||||
public string EventBusConnection { get; set; }
|
||||
}
|
||||
}
|
@ -7,12 +7,11 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Payment.API.IntegrationCommands.Commands;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
||||
using RabbitMQ.Client;
|
||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
||||
using Payment.API.IntegrationEvents;
|
||||
using Payment.API.IntegrationCommands.CommandHandlers;
|
||||
using Payment.API.IntegrationEvents.Events;
|
||||
using Payment.API.IntegrationEvents.EventHandling;
|
||||
|
||||
namespace Payment.API
|
||||
{
|
||||
@ -35,8 +34,7 @@ namespace Payment.API
|
||||
{
|
||||
// Add framework services.
|
||||
services.AddMvc();
|
||||
|
||||
services.AddTransient<IPaymentIntegrationEventService, PaymentIntegrationEventService>();
|
||||
services.Configure<PaymentSettings>(Configuration);
|
||||
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
||||
{
|
||||
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
||||
@ -88,13 +86,15 @@ namespace Payment.API
|
||||
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
||||
|
||||
services.AddTransient<IIntegrationEventHandler<PayOrderCommand>, PayOrderCommandHandler>();
|
||||
services.AddTransient<IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>,
|
||||
OrderStatusChangedToStockConfirmedIntegrationEventHandler>();
|
||||
}
|
||||
|
||||
private void ConfigureEventBus(IApplicationBuilder app)
|
||||
{
|
||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
||||
eventBus.Subscribe<PayOrderCommand, IIntegrationEventHandler<PayOrderCommand>>();
|
||||
eventBus.Subscribe<OrderStatusChangedToStockConfirmedIntegrationEvent,
|
||||
IIntegrationEventHandler<OrderStatusChangedToStockConfirmedIntegrationEvent>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,5 +4,6 @@
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
}
|
||||
},
|
||||
"SuccessPayment": "true"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user