Skip to content

Create Listener\Corellatable interface and Corellating trait #173

@alanbem

Description

@alanbem
interface Correlatable
{
     /**
      * @throws InvalidEventGiven
      */
     public function correlate(Event\Envelope $envelope): Listener\Id;
}
class OrderSaga implements Listener, Listener\Correlatable
{
    use Listener\Correlating;

	public static function correlateByOrderPlaced(OrderPlaced $event): OrderSaga\Id
    {
          return new OrderSaga\Id($event->orderId);
    }

	public static function correlateByInventoryReserved(InventoryReserved $event): OrderSaga\Id
    {
          return new OrderSaga\Id($event->orderId);
    }

    // etc
}
class Factory implements Listener\Factory
{
    public function create(OrderSaga\Id $id): Listener
    {
        return new OrderSaga($id, $this->commandBus);
    }

    /**
     * Somehow automate or make it not part of the factory but part of the Streak infrastructure.
     */ 
    public function createFor(Event\Envelope $envelope): Listener
    {
         return OrderSaga::correlate($envelope);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions