Add log traces for commands
This commit is contained in:
parent
12148c9723
commit
ad7b33234f
@ -66,7 +66,11 @@
|
||||
// Use for Idempotency in Command process
|
||||
public class CreateOrderIdentifiedCommandHandler : IdentifiedCommandHandler<CreateOrderCommand, bool>
|
||||
{
|
||||
public CreateOrderIdentifiedCommandHandler(IMediator mediator, IRequestManager requestManager) : base(mediator, requestManager)
|
||||
public CreateOrderIdentifiedCommandHandler(
|
||||
IMediator mediator,
|
||||
IRequestManager requestManager,
|
||||
ILogger<IdentifiedCommandHandler<CreateOrderCommand, bool>> logger)
|
||||
: base(mediator, requestManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -40,7 +41,11 @@ namespace Ordering.API.Application.Commands
|
||||
// Use for Idempotency in Command process
|
||||
public class SetAwaitingValidationIdentifiedOrderStatusCommandHandler : IdentifiedCommandHandler<SetAwaitingValidationOrderStatusCommand, bool>
|
||||
{
|
||||
public SetAwaitingValidationIdentifiedOrderStatusCommandHandler(IMediator mediator, IRequestManager requestManager) : base(mediator, requestManager)
|
||||
public SetAwaitingValidationIdentifiedOrderStatusCommandHandler(
|
||||
IMediator mediator,
|
||||
IRequestManager requestManager,
|
||||
ILogger<IdentifiedCommandHandler<SetAwaitingValidationOrderStatusCommand, bool>> logger)
|
||||
: base(mediator, requestManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -43,7 +44,11 @@ namespace Ordering.API.Application.Commands
|
||||
// Use for Idempotency in Command process
|
||||
public class SetPaidIdentifiedOrderStatusCommandHandler : IdentifiedCommandHandler<SetPaidOrderStatusCommand, bool>
|
||||
{
|
||||
public SetPaidIdentifiedOrderStatusCommandHandler(IMediator mediator, IRequestManager requestManager) : base(mediator, requestManager)
|
||||
public SetPaidIdentifiedOrderStatusCommandHandler(
|
||||
IMediator mediator,
|
||||
IRequestManager requestManager,
|
||||
ILogger<IdentifiedCommandHandler<SetPaidOrderStatusCommand, bool>> logger)
|
||||
: base(mediator, requestManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -43,7 +44,11 @@ namespace Ordering.API.Application.Commands
|
||||
// Use for Idempotency in Command process
|
||||
public class SetStockConfirmedOrderStatusIdenfifiedCommandHandler : IdentifiedCommandHandler<SetStockConfirmedOrderStatusCommand, bool>
|
||||
{
|
||||
public SetStockConfirmedOrderStatusIdenfifiedCommandHandler(IMediator mediator, IRequestManager requestManager) : base(mediator, requestManager)
|
||||
public SetStockConfirmedOrderStatusIdenfifiedCommandHandler(
|
||||
IMediator mediator,
|
||||
IRequestManager requestManager,
|
||||
ILogger<IdentifiedCommandHandler<SetStockConfirmedOrderStatusCommand, bool>> logger)
|
||||
: base(mediator, requestManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -44,7 +45,11 @@ namespace Ordering.API.Application.Commands
|
||||
// Use for Idempotency in Command process
|
||||
public class SetStockRejectedOrderStatusIdenfifiedCommandHandler : IdentifiedCommandHandler<SetStockRejectedOrderStatusCommand, bool>
|
||||
{
|
||||
public SetStockRejectedOrderStatusIdenfifiedCommandHandler(IMediator mediator, IRequestManager requestManager) : base(mediator, requestManager)
|
||||
public SetStockRejectedOrderStatusIdenfifiedCommandHandler(
|
||||
IMediator mediator,
|
||||
IRequestManager requestManager,
|
||||
ILogger<IdentifiedCommandHandler<SetStockRejectedOrderStatusCommand, bool>> logger)
|
||||
: base(mediator, requestManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -26,7 +27,7 @@ namespace Ordering.API.Application.Commands
|
||||
public async Task<bool> Handle(ShipOrderCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber);
|
||||
if(orderToUpdate == null)
|
||||
if (orderToUpdate == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -40,7 +41,11 @@ namespace Ordering.API.Application.Commands
|
||||
// Use for Idempotency in Command process
|
||||
public class ShipOrderIdentifiedCommandHandler : IdentifiedCommandHandler<ShipOrderCommand, bool>
|
||||
{
|
||||
public ShipOrderIdentifiedCommandHandler(IMediator mediator, IRequestManager requestManager) : base(mediator, requestManager)
|
||||
public ShipOrderIdentifiedCommandHandler(
|
||||
IMediator mediator,
|
||||
IRequestManager requestManager,
|
||||
ILogger<IdentifiedCommandHandler<ShipOrderCommand, bool>> logger)
|
||||
: base(mediator, requestManager, logger)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ordering.API.Application.Behaviors;
|
||||
using Ordering.API.Application.Commands;
|
||||
using Ordering.API.Application.IntegrationEvents.Events;
|
||||
using Serilog.Context;
|
||||
@ -38,6 +39,14 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppShortName} - ({@IntegrationEvent})", @event.Id, Program.AppShortName, @event);
|
||||
|
||||
var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
command.GetGenericTypeName(),
|
||||
nameof(command.OrderNumber),
|
||||
command.OrderNumber,
|
||||
command);
|
||||
|
||||
await _mediator.Send(command);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ordering.API.Application.Behaviors;
|
||||
using Ordering.API.Application.Commands;
|
||||
using Ordering.API.Application.IntegrationEvents.Events;
|
||||
using Serilog.Context;
|
||||
@ -32,6 +33,14 @@
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppShortName} - ({@IntegrationEvent})", @event.Id, Program.AppShortName, @event);
|
||||
|
||||
var command = new CancelOrderCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
command.GetGenericTypeName(),
|
||||
nameof(command.OrderNumber),
|
||||
command.OrderNumber,
|
||||
command);
|
||||
|
||||
await _mediator.Send(command);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ordering.API.Application.Behaviors;
|
||||
using Ordering.API.Application.Commands;
|
||||
using Ordering.API.Application.IntegrationEvents.Events;
|
||||
using Serilog.Context;
|
||||
@ -32,6 +33,14 @@
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppShortName} - ({@IntegrationEvent})", @event.Id, Program.AppShortName, @event);
|
||||
|
||||
var command = new SetPaidOrderStatusCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
command.GetGenericTypeName(),
|
||||
nameof(command.OrderNumber),
|
||||
command.OrderNumber,
|
||||
command);
|
||||
|
||||
await _mediator.Send(command);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Context;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
using Ordering.API.Application.Behaviors;
|
||||
|
||||
public class OrderStockConfirmedIntegrationEventHandler :
|
||||
IIntegrationEventHandler<OrderStockConfirmedIntegrationEvent>
|
||||
@ -32,6 +33,14 @@
|
||||
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppShortName} - ({@IntegrationEvent})", @event.Id, Program.AppShortName, @event);
|
||||
|
||||
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId);
|
||||
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
command.GetGenericTypeName(),
|
||||
nameof(command.OrderNumber),
|
||||
command.OrderNumber,
|
||||
command);
|
||||
|
||||
await _mediator.Send(command);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog.Context;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
using Ordering.API.Application.Behaviors;
|
||||
|
||||
public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandler<OrderStockRejectedIntegrationEvent>
|
||||
{
|
||||
@ -36,6 +37,14 @@
|
||||
.ToList();
|
||||
|
||||
var command = new SetStockRejectedOrderStatusCommand(@event.OrderId, orderStockRejectedItems);
|
||||
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
command.GetGenericTypeName(),
|
||||
nameof(command.OrderNumber),
|
||||
command.OrderNumber,
|
||||
command);
|
||||
|
||||
await _mediator.Send(command);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Ordering.API.Application.IntegrationEvents.Events;
|
||||
using Serilog.Context;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API;
|
||||
using Ordering.API.Application.Behaviors;
|
||||
|
||||
namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
{
|
||||
@ -51,7 +52,12 @@ namespace Ordering.API.Application.IntegrationEvents.EventHandling
|
||||
|
||||
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(createOrderCommand, @event.RequestId);
|
||||
|
||||
_logger.LogInformation("----- IdentifiedCreateOrderCommand: {@IdentifiedCreateOrderCommand}", requestCreateOrder);
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
requestCreateOrder.GetGenericTypeName(),
|
||||
nameof(requestCreateOrder.Id),
|
||||
requestCreateOrder.Id,
|
||||
requestCreateOrder);
|
||||
|
||||
result = await _mediator.Send(requestCreateOrder);
|
||||
|
||||
|
@ -4,6 +4,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ordering.API.Application.Behaviors;
|
||||
using Ordering.API.Application.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -20,12 +22,18 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IOrderQueries _orderQueries;
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly ILogger<OrdersController> _logger;
|
||||
|
||||
public OrdersController(IMediator mediator, IOrderQueries orderQueries, IIdentityService identityService)
|
||||
public OrdersController(
|
||||
IMediator mediator,
|
||||
IOrderQueries orderQueries,
|
||||
IIdentityService identityService,
|
||||
ILogger<OrdersController> logger)
|
||||
{
|
||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||
_orderQueries = orderQueries ?? throw new ArgumentNullException(nameof(orderQueries));
|
||||
_identityService = identityService ?? throw new ArgumentNullException(nameof(identityService));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
[Route("cancel")]
|
||||
@ -39,6 +47,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
|
||||
{
|
||||
var requestCancelOrder = new IdentifiedCommand<CancelOrderCommand, bool>(command, guid);
|
||||
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
requestCancelOrder.GetGenericTypeName(),
|
||||
nameof(requestCancelOrder.Command.OrderNumber),
|
||||
requestCancelOrder.Command.OrderNumber,
|
||||
requestCancelOrder);
|
||||
|
||||
commandResult = await _mediator.Send(requestCancelOrder);
|
||||
}
|
||||
|
||||
@ -61,6 +77,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
if (Guid.TryParse(requestId, out Guid guid) && guid != Guid.Empty)
|
||||
{
|
||||
var requestShipOrder = new IdentifiedCommand<ShipOrderCommand, bool>(command, guid);
|
||||
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
requestShipOrder.GetGenericTypeName(),
|
||||
nameof(requestShipOrder.Command.OrderNumber),
|
||||
requestShipOrder.Command.OrderNumber,
|
||||
requestShipOrder);
|
||||
|
||||
commandResult = await _mediator.Send(requestShipOrder);
|
||||
}
|
||||
|
||||
@ -114,6 +138,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<OrderDraftDTO>> CreateOrderDraftFromBasketDataAsync([FromBody] CreateOrderDraftCommand createOrderDraftCommand)
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
|
||||
createOrderDraftCommand.GetGenericTypeName(),
|
||||
nameof(createOrderDraftCommand.BuyerId),
|
||||
createOrderDraftCommand.BuyerId,
|
||||
createOrderDraftCommand);
|
||||
|
||||
return await _mediator.Send(createOrderDraftCommand);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
<UserSecretsId>aspnet-Ordering.API-20161122013547</UserSecretsId>
|
||||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
|
||||
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
<NoWin32Manifest>true</NoWin32Manifest>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -67,9 +67,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task BeginTransactionAsync()
|
||||
public async Task<IDbContextTransaction> BeginTransactionAsync()
|
||||
{
|
||||
_currentTransaction = _currentTransaction ?? await Database.BeginTransactionAsync(IsolationLevel.ReadCommitted);
|
||||
|
||||
return _currentTransaction;
|
||||
}
|
||||
|
||||
public async Task CommitTransactionAsync()
|
||||
|
Loading…
x
Reference in New Issue
Block a user