Git Product home page Git Product logo

Comments (6)

frankdejonge avatar frankdejonge commented on May 27, 2024

I'll have a think about it. I personally don't use the required history and adding a method specifically for this seems a bit overkill. An option could also be to wrap the AggregateRootRepository into something that DOES hint it can through this, would that work for you?

from eventsauce.

patrickkusebauch avatar patrickkusebauch commented on May 27, 2024

I feel that the root of the problem is that:

    public function retrieve(AggregateRootId $aggregateRootId): object;

in AggregateRootRepository does not return ?object. This would be the behavior I would expect (and have seen) for pretty much any Storage system.

If I ask for something and it does not exist, let me know. right now it auto-magically will create it. This might be intended behavior for some cases, but it is IMHO very non-intuitive. And it results in this situation with incompatible implementations.

But you could have the intuitive behavior:

interface AggregateRootRepository
{
    public function retrieve(AggregateRootId $aggregateRootId): ?object;
}

and 2 implementations, one that returns ?object and another that returns object. No exception, no incompatibilities.

from eventsauce.

patrickkusebauch avatar patrickkusebauch commented on May 27, 2024

and if you feel like having only one ConstructingAggregateRootRepository, you could even template it like this:

/**
 * @template T of bool
 */
class ConstructingAggregateRootRepository
{
    /**
      * @param T $constructOnNoneExistant
      */
    public function __construct(
        string $aggregateRootClassName,
        MessageRepository $messageRepository,
        MessageDispatcher $dispatcher = null,
        MessageDecorator $decorator = null,
        bool $constructOnNoneExistant = true
    )
    
    /*
     * @return (T is true ? object : ?object)
     */
    public function retrieve(AggregateRootId $aggregateRootId): ?object

}

from eventsauce.

patrickkusebauch avatar patrickkusebauch commented on May 27, 2024

In terms of BC breaks:

  • functionally it is the same (at runtime, the same output for the same inputs as the old code)
  • ConstructingAggregateRootRepository is final, so more constructor parameters are OK
  • The SA is very different. However, for the 2 most widely used (Psalm and PHPStan) it would just ask for template types if the repository is assigned to a variable or being a return type.

from eventsauce.

HellPat avatar HellPat commented on May 27, 2024

Related to #48
There is a detailed explanation.

from eventsauce.

driesvints avatar driesvints commented on May 27, 2024

This will be fixed in v1.0. Thanks all.

from eventsauce.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.