prooph / event-store-symfony-bundle

Event Store Symfony Bundle

Home Page:http://getprooph.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Projections defined as services cannot be found

Miljar opened this issue · comments

On Symfony4 and event-store-symfony-bundle 0.4, it's not possible to define your projections as a service, and then run them.

Example service definition:

    Argus\Domain\User\Projection\CredentialsProjection:
        public: true
        class: Argus\Domain\User\Projection\CredentialsProjection
        arguments: ['@fos_user.util.user_manipulator']
        tags:
            - { name: 'prooph_event_store.projection', projection_name: 'user_credentials_projection', projection_manager: 'argus_projection_manager', read_model: 'Argus\Domain\User\Projection\CredentialsReadModel' }

Projections are expected to be added to the event store via the config. Example:

    projection_managers:
        argus_projection_manager:
            event_store: Prooph\EventStore\Pdo\MySqlEventStore # event store
            connection: 'doctrine.pdo.connection'
            projections:
                user_credentials_projection:
                    projection: Argus\Domain\User\Projection\CredentialsProjection

This configuration causes the ProophEventStoreExtension class to create new services in the container with id prooph_event_store.projection.<projection name> and given projection class.

Since Symfony4, multiple service definitions for the same class are not allowed. So the existing service definition cancels out the creation of the prooph_event_store.projection.<projeciton name>one, which results in an empty Locator service that is being used by the AbstractProjectionCommand.

Current workaround is to:

  • Manually create an alias prooph_event_store.projection.<projection name> for the service which is already defined for the projection class
  • Add the projection to the configuration, as is expected by this bundle

My suggested fix would be:

  • Create a map of projection_name => projection_class from the list of services tagged with prooph_event_store.projection
  • Before creating the new definition for the given Projection class, check if it exists in the map. If it does, create an alias instead (if that alias also doesn't exist)