Calling commands from another Handle () method

Hi I am using the Simple Injector DI library and have been following some really interesting materials about the architectural model developed around the command template:

The container will manage the lifetime UnitOfWork, and I use the commands to perform certain functions in the database.

My question is whether I have a team, for example AddNewCustomerCommand, which, in turn, makes another call to another service (i.e. sends a text message), from the point of view of design, is this acceptable or should it be done at a higher level, and if so, how is this best done?

Sample code below:

public class AddNewBusinessUnitHandler
    : ICommandHandler<AddBusinessUnitCommand>
{
    private IUnitOfWork uow;
    private ICommandHandler<OtherServiceCommand> otherHandler;

    AddNewBusinessUnitHandler(IUnitOfWork uow, 
        ICommandHandler<OtherServiceCommand> otherHandler)
    {
        this.uow = uow;
        this.otherHandler = otherHandler;
    }

     public void Handle(AddBusinessUnitCommand command)
     {
        var businessUnit = new BusinessUnit()
        {
            Name = command.BusinessUnitName,
            Address = command.BusinessUnitAddress
        };

        var otherCommand = new OtherServiceCommand()
        {
            welcomePostTo = command.BusinessUnitName
        };

        uow.BusinessUnitRepository.Add(businessUnit);

        this.otherHandler.Handle(otherCommand);
     }
}
+5
1

(), Use Case . ( , ) , . , , , . , , .

, , , , - , , (, , ). , , , , .

, . , , . ITextMessageSender, .

- . , , , . , .

, -, , , . , ITextSessageSender ICommandHandler<SendTextMessageCommand>, .

, , , , . , , , , , . . , , . , , .

, - , /, . DeadlockRetryCommandHandlerDecorator ), .

+14

All Articles