Ejemplo n.º 1
0
    public static async Task HandleCreateCommand <TCommand>(
        EventStoreClient eventStore,
        Func <TCommand, object> handle,
        Func <TCommand, string> getId,
        TCommand command,
        CancellationToken ct
        )
    {
        var entityId = getId(command);
        var @event   = handle(command);

        await eventStore.Append(entityId, @event, ct);
    }
Ejemplo n.º 2
0
    public static async Task HandleUpdateCommand <TCommand, TEntity>(
        EventStoreClient eventStore,
        Func <TEntity> getDefault,
        Func <TEntity, object, TEntity> when,
        Func <TCommand, TEntity, object> handle,
        Func <TCommand, string> getId,
        Func <TCommand, uint> getVersion,
        TCommand command,
        CancellationToken ct) where TEntity : notnull
    {
        var id     = getId(command);
        var entity = await eventStore.Find(getDefault, when, id, ct);

        var @event = handle(command, entity);

        await eventStore.Append(id, @event, getVersion(command), ct);
    }