Skip to content

Commit fd2bf42

Browse files
committed
Add creation event traces to Validator classes to validate issue dotnet-architecture#1041
1 parent aee4d91 commit fd2bf42

5 files changed

Lines changed: 25 additions & 20 deletions

File tree

docker-compose.override.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ services:
111111
- OrchestratorType=${ORCHESTRATOR_TYPE}
112112
- UseLoadTest=${USE_LOADTEST:-False}
113113
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
114+
- Serilog__MinimumLevel__Override__Ordering.API=Verbose
114115
ports:
115116
- "5102:80" # Important: In a production environment your should remove the external port (5102) kept here for microservice debugging purposes.
116117
# The API Gateway redirects and access through the internal port (80).
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
using FluentValidation;
2+
using Microsoft.Extensions.Logging;
23
using Ordering.API.Application.Commands;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Threading.Tasks;
74

85
namespace Ordering.API.Application.Validations
96
{
107
public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
118
{
12-
public CancelOrderCommandValidator()
9+
public CancelOrderCommandValidator(ILogger<CancelOrderCommandValidator> logger)
1310
{
1411
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
12+
13+
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
1514
}
1615
}
17-
}
16+
}

src/Services/Ordering/Ordering.API/Application/Validations/CreateOrderCommandValidator.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FluentValidation;
22
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
3+
using Microsoft.Extensions.Logging;
34
using System;
45
using System.Collections.Generic;
56
using System.Linq;
@@ -9,19 +10,21 @@ namespace Ordering.API.Application.Validations
910
{
1011
public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
1112
{
12-
public CreateOrderCommandValidator()
13+
public CreateOrderCommandValidator(ILogger<CreateOrderCommandValidator> logger)
1314
{
1415
RuleFor(command => command.City).NotEmpty();
1516
RuleFor(command => command.Street).NotEmpty();
1617
RuleFor(command => command.State).NotEmpty();
1718
RuleFor(command => command.Country).NotEmpty();
1819
RuleFor(command => command.ZipCode).NotEmpty();
19-
RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19);
20+
RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19);
2021
RuleFor(command => command.CardHolderName).NotEmpty();
21-
RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date");
22-
RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3);
22+
RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date");
23+
RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3);
2324
RuleFor(command => command.CardTypeId).NotEmpty();
24-
RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found");
25+
RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found");
26+
27+
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
2528
}
2629

2730
private bool BeValidExpirationDate(DateTime dateTime)
@@ -34,4 +37,4 @@ private bool ContainOrderItems(IEnumerable<OrderItemDTO> orderItems)
3437
return orderItems.Any();
3538
}
3639
}
37-
}
40+
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using FluentValidation;
22
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
3+
using Microsoft.Extensions.Logging;
34

45
namespace Ordering.API.Application.Validations
56
{
67
public class IdentifiedCommandValidator : AbstractValidator<IdentifiedCommand<CreateOrderCommand,bool>>
78
{
8-
public IdentifiedCommandValidator()
9+
public IdentifiedCommandValidator(ILogger<IdentifiedCommandValidator> logger)
910
{
10-
RuleFor(command => command.Id).NotEmpty();
11+
RuleFor(command => command.Id).NotEmpty();
12+
13+
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
1114
}
1215
}
1316
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
using FluentValidation;
2+
using Microsoft.Extensions.Logging;
23
using Ordering.API.Application.Commands;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Threading.Tasks;
74

85
namespace Ordering.API.Application.Validations
96
{
107
public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
118
{
12-
public ShipOrderCommandValidator()
9+
public ShipOrderCommandValidator(ILogger<ShipOrderCommandValidator> logger)
1310
{
1411
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
12+
13+
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
1514
}
1615
}
17-
}
16+
}

0 commit comments

Comments
 (0)