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

Not working with one stream for all #34

Open
prolic opened this issue Apr 30, 2018 · 2 comments
Open

Not working with one stream for all #34

prolic opened this issue Apr 30, 2018 · 2 comments
Labels

Comments

@prolic
Copy link
Member

prolic commented Apr 30, 2018

See prooph/proophessor-do#158

@prolic prolic added the bug label Apr 30, 2018
@basz
Copy link
Member

basz commented Jul 7, 2021

Hi!

I think I'm hitting this too. I recently introduced multiple aggregate types in one stream and noticed some snapshotters are not running. I have created a patch that seems to solve it. But as this package is deprecated (and my patch isn't backwards compatible) what are the changes this would get merged and released?

The gist of it is; instead of CustomerRepository accepting a single aggregateRepository and multiple types I tweaked it into accepting multiple repositories.

SnapshotReadModelFactory

public function __invoke(ContainerInterface $container): SnapshotReadModel
{
    return new SnapshotReadModel(
        [
            $container->get(CustomerRepository::class),
            $container->get(OrderLeadRepository::class)
        ],
        new AggregateTranslator(),
        $snapshotStore,
        [
            \HF\Api\Domain\Customer\Aggregate\Customer::class,
            \HF\Api\Domain\Customer\Aggregate\OrderLead::class,
        ]
    );
}

and the changed the persist method to try all repositories

SnapshotReadModel::persist

public function persist(): void
    {
        foreach (\array_unique($this->aggregateCache) as $aggregateId) {
            foreach($this->aggregateRepositories as $aggregateRepository) {
                $aggregateRoot = $aggregateRepository->getAggregateRoot($aggregateId);

                if ($aggregateRoot) {
                    break;
                }
            }

            $this->snapshotStore->save(new Snapshot(
                (string) AggregateType::fromAggregateRoot($aggregateRoot),
                $aggregateId,
                $aggregateRoot,
                $this->aggregateTranslator->extractAggregateVersion($aggregateRoot),
                new \DateTimeImmutable('now', new \DateTimeZone('UTC'))
            ));
        }

        foreach($this->aggregateRepositories as $aggregateRepository) {
            $aggregateRepository->clearIdentityMap();
        }

        $this->aggregateCache = [];
    }

@prolic
Copy link
Member Author

prolic commented Aug 31, 2021

instead of going

[
    $container->get(CustomerRepository::class),
    $container->get(OrderLeadRepository::class)
]

can we use a AggregateRepository implementation that wraps multiple repository inside itself?

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