contributte / event-dispatcher

:boom: Best events support (symfony/event-dispatcher) to Nette Framework (@nette)
https://contributte.org/packages/contributte/event-dispatcher.html
MIT License
28 stars 8 forks source link

Multiple services of type Symfony\Component\EventDispatcher\EventDispatcherInterface found #7

Closed JanMikes closed 6 years ago

JanMikes commented 6 years ago

Hi, after replacing symplify/symfony-event-dispatcher with contributte/event-dispatcher i am getting following error: Nette\DI\ServiceCreationException: Multiple services of type Symfony\Component\EventDispatcher\EventDispatcherInterface found: events.symfonyProxy, _21.dispatcher

It is because i am using Kdyby/Events in my project and it registers symfony event dispatcher as well.

This problem was already solved in symplify https://github.com/DeprecatedPackages/SymfonyEventDispatcher/blob/master/src/Adapter/Nette/DI/SymfonyEventDispatcherExtension.php#L42

Do you plan to fix it? Or any other tips how to get rid of Kdyby/Events? 😄

Thank you

f3l1x commented 6 years ago

Well, I do not think its a bug. Rather than internally remove duplicate service (Kdyby), I would disable autowiring for that service.

What do you think? Why are you using this package with Kdyby/Events.

JanMikes commented 6 years ago

Yeah, that seems reasonable, i will try to update the PR.

Unfortunately i need doctrine events in my project. I am dispatching domain events (exactly this way) from my entities and i do not know about any other doctrine events implementation into nette at this moment.

f3l1x commented 6 years ago

Don't get me wrong, I still think it's better to disable autowiring directly in your app's config. You're are using Kdyby\Events + Contributte\EventDispatcher together, you have to handle it by your self.

services:
  kdyby_events.dispatcher:
    autowire: off # or self

It's preferable way for me. No hidden magic.

JanMikes commented 6 years ago

Ah sure, thank you, this works. Just to make it correct, this is exactly what has to be added to config:

services:
    events.symfonyProxy:
        autowired: off
f3l1x commented 6 years ago

Thanks anyway.