JorgeeFG
JorgeeFG

Reputation: 5981

Symfony 3 use parameters in class that is not a service

I have a service that instantiates other classes.

I would like to parametrize a $url variable in those classes (different URL by class).

How could I access a parameter from a class that is not a service?

I could make those classes a service, but it would only be because of parameters, because they should not be stand alone services.

How could I solve this?

Upvotes: 0

Views: 119

Answers (1)

fgamess
fgamess

Reputation: 1324

If you want to access parameters in a class you need to inject the Container (not a good idea because, it will inject the entire Container just for parameters) or just inject the concerned parameters directly, right ? Like you said, it's necessary to declare your class as a service to use these parameters. If you think it is heavy to declare your class as a service to access these parameters, why don't you use Lazy Services ?

Upvotes: 1

Related Questions