Skip to content

Conversation

the-avid-engineer
Copy link
Member

@the-avid-engineer the-avid-engineer commented Mar 2, 2022

The idea of ICommand<TEntity> being a reducer was an opinionated abstraction, which is something I do want to avoid. To that end, I have removed the ICommand interface and added a Reduce method to the IEntity<TEntity> interface (which lives in the Common library, and can therefore be opinionated). All of the methods (other than the reducer) which took ICommand<TEntity> now take object

By default, this means that reduction is centralized to the entity for which the commands are relevant. However, consumers may still decentralize the reduction process by having their commands implement IReducer<TEntity> (new to the Abstractions library) and un-box the commands like this:

public TEntity Reduce(object[] commands)
{
    var newEntity = this;

    foreach (var command in commands)
    {
        if (command is not IReducer<TransactionEntity> reducer)
        {
            throw new NotImplementedException();
        }
        
        newEntity = reducer.Reduce(newEntity);
    }

    return newEntity;
}

The difference is that decentralization is no longer mandatory.

consumer is free to choose wether they want a centralized or decentralized reduction process; provide a useful IReducer interface out of the box to work similar to before
@the-avid-engineer the-avid-engineer merged commit 20185ad into main Mar 2, 2022
@the-avid-engineer the-avid-engineer deleted the feat/better-reducer branch March 2, 2022 19:09
@the-avid-engineer the-avid-engineer self-assigned this Jun 25, 2022
@the-avid-engineer the-avid-engineer added diff:add Code has been added diff:refactor:break Code has been refactored in a way that will cause compiler errors and does not fix a bug diff:remove Pull Request removes an existing feature labels Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diff:add Code has been added diff:refactor:break Code has been refactored in a way that will cause compiler errors and does not fix a bug diff:remove Pull Request removes an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant