I have the following service definition in Symfony2
app.service_1:
class: Symfony\Component\Lock\Store\RedisStore
arguments:
- '@snc_redis.default_cache'
app.service_2:
class: Symfony\Component\Lock\Store\RedisStore
arguments:
- '@snc_redis.scheduler_cache'
Now I'm planning to upgrade to Symnfony4 where I need to give classpath as the service name
Symfony\Component\Lock\Store\RedisStore
arguments:
- '@snc_redis.default_cache'
Symfony\Component\Lock\Store\RedisStore
arguments:
- '@snc_redis.scheduler_cache'
Here the problem is it has the same name because we use the same classpath? How I can fix it? Can I use an alias with different parameters?
You do not need to change the definition.
When you need to create several services from the same class, using the FQCN as an identifier won't work. Using the fully qualified class name is recommended and a good practice, but it's not mandatory. It's practical most of the time, since you can omit the
class
argument, and you do not need to pick a name for each service.Your original definition is perfectly compatible with Symfony 4 (or 5):
I would simply advise to use more descriptive identifiers than
service_1
andservice_2
.