public async Task <bool> Handle(CreateApplicationCommand message, CancellationToken cancellationToken) { // Add Integration event to clean the basket var applicationStartedIntegrationEvent = new ApplicationStartedIntegrationEvent(message.UserId); await _applyingIntegrationEventService.AddAndSaveEventAsync(applicationStartedIntegrationEvent); // Add/Update the Student AggregateRoot // DDD patterns comment: Add child entities and value-objects through the Application Aggregate-Root // methods and constructor so validations, invariants and business logic // make sure that consistency is preserved across the whole aggregate var profile = new Profile(message.IDNumber, message.Request); var application = new Application(message.UserId, message.UserName, profile, message.PaymentTypeId); foreach (var item in message.ApplicationItems) { application.AddApplicationItem(item.ScholarshipItemId, item.ScholarshipItemName, item.SlotAmount, item.PictureUrl, item.Slots); } _logger.LogInformation("----- Creating Application - Application: {@Application}", application); _applicationRepository.Add(application); return(await _applicationRepository.UnitOfWork .SaveEntitiesAsync(cancellationToken)); }