Rename Symfony service to use Class name instead of 'cocur_slugify'
raffomania opened this issue · 7 comments
Using symfony 3.4, I get the following deprecation warning:
Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "cocur_slugify" service to "Cocur\Slugify\SlugifyInterface" instead.
Symfony now expects services to be named according to their fully qualified classname. This should be an easy and backwards compatible fix to make.
Just use SlugifyInterface
in your constructor instead of Slugify
This works, but leaves out services that don't use autowiring. Since FQCN naming is the officially recommended way forward, wouldn't it make sense to use it? You could just alias the old service to the up-to-date definition to stay backwards compatible.
Not sure about that, just type bin/console debug:container --types
and you'll see there's plenty of services that use interfaces.
If you don't use autowiring, you can still inject the service and use SlugifyInterface as argument.
@raffomania
I had this same error at work with some legacy code, and resolved it exactly by doing this advice.
Had no problem with some other services declared manually.
It's common, and good practice, to expect interfaces and inject a concrete implementation.
It's more DI-friendly and avoids unnecessary coupling.
I will set up the FQCN in the new bundle and add an alias for cocur_slugify.
Do we need to keep this issue open ?
@FabienPapet You're right, this should have been fixed with 4.0