Edition 0 Updated to asp. Net core 0
Yüklə
11,82 Mb.
Pdf görüntüsü
səhifə
231/288
tarix
12.07.2023
ölçüsü
11,82 Mb.
#136458
1
...
227
228
229
230
231
232
233
234
...
288
public
class
CreateOrderCommandHandler
: IRequestHandler
bool
>
{
private
readonly
IOrderRepository _orderRepository;
private
readonly
IIdentityService _identityService;
private
readonly
IMediator _mediator;
private
readonly
IOrderingIntegrationEventService _orderingIntegrationEventService;
private
readonly
ILogger
_logger;
// Using DI to inject infrastructure persistence Repositories
public
CreateOrderCommandHandler
(IMediator mediator,
IOrderingIntegrationEventService orderingIntegrationEventService,
IOrderRepository orderRepository,
IIdentityService identityService,
ILogger
logger)
{
_orderRepository = orderRepository ??
throw
new
ArgumentNullException
(
nameof
(orderRepository));
_identityService = identityService ??
throw
new
ArgumentNullException
(
nameof
(identityService));
_mediator = mediator ??
throw
new
ArgumentNullException
(
nameof
(mediator));
_orderingIntegrationEventService = orderingIntegrationEventService ??
throw
new
ArgumentNullException
(
nameof
(orderingIntegrationEventService));
_logger = logger ??
throw
new
ArgumentNullException
(
nameof
(logger));
}
public
async Task<
bool
>
Handle
(CreateOrderCommand message, CancellationToken
cancellationToken)
{
// Add Integration event to clean the basket
var
orderStartedIntegrationEvent =
new
OrderStartedIntegrationEvent
(message.
UserId
);
await
_orderingIntegrationEventService.
AddAndSaveEventAsync
(orderStartedIntegrationEvent);
// Add/Update the Buyer AggregateRoot
// DDD patterns comment: Add child entities and value-objects through the Order
Aggregate-Root
// methods and constructor so validations, invariants and business logic
// make sure that consistency is preserved across the whole aggregate
var
address =
new
Address
(message.
Street
, message.
City
, message.
State
,
message.
Country
, message.
ZipCode
);
var
order =
new
Order
(message.
UserId
, message.
UserName
, address,
message.
CardTypeId
, message.
CardNumber
, message.
CardSecurityNumber
, message.
CardHolderName
,
message.
CardExpiration
);
270
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
Yüklə
11,82 Mb.
Dostları ilə paylaş:
1
...
227
228
229
230
231
232
233
234
...
288
Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət
gir
|
qeydiyyatdan keç
Ana səhifə
Stomatologiya
Anesteziologiya
Cərrahlıq
Ginekologiya
Tibb
yükləyin