adr/2024_10_03_services_naming_convention.md
Services in Sylius are named in different ways, depending on the time of their creation, and other services' names.
Also, some services named with using the dot notation are harder to be used with autowire feature.
autowire featuredot notationThis variant is the most common way of naming services in Sylius from the beginning.
It was the only considered option in Symfony-based projects before the autowire feature was introduced.
#[Autowire] attribute to inject servicesThis variant of naming appeared along with introducing the autowire feature in Symfony.
It makes using services easier, but at the same time introduces a little bit magic to the code.
autowire featuredot notationdot notation with the FQCN (when it makes sense)This variant is a combination of the previous two options, but it considers declaring the FQCN alias only when it makes sense.
The FQCN alias should be declared only for services that implement a non-generic interface.
Some services that are not meant to be used with the autowire feature should continue to be named with the dot notation, including:
For services that adhere to the Composite pattern, the FQCN alias should be declared for the composite service, and the alias should be based on the interface name.
This ensures clarity in identifying composite services while maintaining a consistent and logical structure.
dot notation for many services, so we do not have to rename themFQCN will still workChosen option: "Combine the dot notation with the FQCN (when it makes sense)"
Despite the fact that it requires more work, it is the best option to provide a consistent way of naming services and support the autowire feature.
Also, thanks to this approach, we stay consistent with the Symfony best practices.
<services>
<service id="sylius_admin.resolver.some" class="Sylius\Bundle\AdminBundle\Resolver\SomeResolver" />
<service id="Sylius\Bundle\AdminBundle\Resolver\ResolverInterface" alias="sylius_admin.resolver.some" />
</services>