0

I try to build an app using the following layers

Controllers <-> Application Services <-> Domain Services 
                                     <-> Infrastructure

Some validation might happen in the Domain Services and I am trying to find o a way of getting such information to the Application Service which will send it back to its caller and so on.

One way that I am trying right now is that my Domain Service would return a list of events and one of the events would by a Validation event.

So in my Application Service reading events I can figure out if any validation happened

Question:

How Ok do you thing is such strategy?

  • 1
    One little comment: the domain layer should not depend (in any way!) to the other layers – Constantin Galbenu Sep 22 '17 at 11:57
  • What happens if the validation fails? the command is rejected? – Constantin Galbenu Sep 22 '17 at 11:58
  • Yes. It'up to the command process code (where from the service domain was called) to decide what to do: fail and send it back to controller, retry next hour, etc – user237329 Sep 22 '17 at 14:54
  • Where do you think that the Domain layers depends on other layers? – user237329 Sep 22 '17 at 15:00
  • Domain Services <-> Infrastructure – Constantin Galbenu Sep 22 '17 at 15:27
1

I assume the validation error indicates the domain service is prevented from completing the requested task. In that case an event is not appropriate. An even indicate some thing happened and other systems may want to react to this, but nobody is required to react.

But in this case the caller have to react to the error, and the result is simply not meaningful otherwise. So I think the correct approach is an exception, or some kind of Option type which indicate either a successful execution of the task or the validation error which prevented it.

  • I see where your going to. One of my problem with exceptions is the fact that validation is not really an exception , it's actually part of the bussiness: in domain you validate complex logic. – user237329 Sep 22 '17 at 14:58
  • @user237329 Exceptions were a way of handling "this did not go as planned". You could have two kinds of problem-catchers, 1) "this was anticipated but I still have to fix it", and 2) "this was really not part of the flow the application is expected to handle". Your idea of creating events that the app receives could work, but is it more or less complex than catching all exceptions in one place? Your idea might well be better. – user251748 Sep 22 '17 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.