Common DDD and Domain-specific Events

I consider domain events, in particular in two ways:

a. Use of such "general" events:

public class OrderStateChangedEvent : IEvent
{
  public Guid OrderId { get; }
  public OrderState NewState { get; }
}

then the consumer will determine the new state and do something. Since I use Rx, it will not be that difficult (and better than a switch / case):

var subscription = DomainEvents
     .AsObservable<OrderStateChangedEvent>()
     .Where(e => e.NewState == OrderState.OrderCompleted)
     .Subscribe(OnOrderCompleted);

B. Use of certain events:

public class OrderCompletedEvent : IEvent
{
  public Guid OrderId { get; }
}

this will lead to even more event classes, which, on the one hand, can get too much, on the other hand, event class names contain a language, and this can be a plus point.

Do you have any recommendations? I am not familiar with domain events and cannot make a qualified decision here (both seem to have no serious flaws)

+4
2

, "" . , "" .

, - , , - , .

+1

, switch OO.

http://c2.com/cgi/wiki?SwitchStatementsSmell

. , , :

var subscription = DomainEvents
   .AsObservable<OrderCompletedEvent>()
   .Subscribe(OnOrderCompleted);
+1

Source: https://habr.com/ru/post/1615795/


All Articles