Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AggregateRepository::aggregateType attribute not initialized in the constructor #32

Closed
dottorbabba opened this issue Oct 29, 2014 · 2 comments
Labels

Comments

@dottorbabba
Copy link
Contributor

Hi, I'm constructing my instance of AggregateRepository in this way:

class EventSourcingProjectService extends AggregateRepository implements ProjectService
{
    public function __construct(EventStore $eventStore, StreamStrategyInterface $eventStoreStrategy) {
        parent::__construct($eventStore, new AggregateTranslator(), $eventStoreStrategy, new AggregateType('Ora\ProjectManagement\Project'));
    }

    public function findProject($id)
    {
        $project = $this->getAggregateRoot($this->aggregateType, $id);
        return $project;
    }
} 

but when I call findProject, I got the following error:

Argument 1 passed to Prooph\EventStore\Aggregate\AggregateRepository::getAggregateRoot() must be an instance of Prooph\EventStore\Aggregate\AggregateType, null given"

Looking at the source code, the constructor of AggregateRepository does not initialize aggregateType attribute with the value passed to. Is it correct?

Thank you very much
Andrea

@codeliner codeliner added the bug label Oct 29, 2014
@codeliner
Copy link
Member

This is definitely a bug. The way you want to use it is correct.

I always do it this way:

class EventSourcingProjectService extends AggregateRepository implements ProjectService
{
    public function __construct(EventStore $eventStore, StreamStrategyInterface $eventStoreStrategy) {
        $this->aggregateType = new AggregateType('Ora\ProjectManagement\Project');
        parent::__construct($eventStore, new AggregateTranslator(), $eventStoreStrategy);
    }

    public function findProject($id)
    {
        $project = $this->getAggregateRoot($this->aggregateType, $id);
        return $project;
    }
} 

So I have not recognized the bug. I will fix this immediatly and release a new version. Thanks for pointing it out.

@codeliner
Copy link
Member

Ok, release is available. v1.1.1 should solve the problem. The fix was already available on master. I fixed it last weekend but have forgotten to draft a new release. To much parallel work at the moment :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants