I have a Provision
, this Provision
has state with relative constraints. For example: I can accept a Provision
only if its actual state is authorized.
Since this is clearly a business rule I code it inside my domain model:
public void Accept()
{
if (this.State == ProvisionsState.Authorized)
this.State = ProvisionsState.Accepted;
else
throw new InvalidOperationForProvision("The provision have to be authorized.");
}
So far so good, but... I have a command (a sort of DTO with only the ProvisionId
) and a relative handler. When a client wants to accept a provision will put AcceptCommand
DTO on a bus. Right now the AcceptCommandHandler
take this command from the bus and handle it.
public void Handle(AcceptCommand command)
{
var provision = Repository.GetById(command.ProvisionId);
provision.Accept();
...
}
If the InvalidOperationForProvision
isn't raised everything will be ok and ProvisionAcceptedEvent
will be send. So far so good (as far as I know). But the question is: what happens if exception is raised?
Bearing in mind that some bus will retry the command many times, even if the command will surely fail (eg: a disabled provision will never be authorized, so I will never accept it, but the accept command will still be there).