I don't think that accessing parameters from a service is the better choice. I will suggest you rather to define your parameter in the "bind" section of service.yaml file like this
services:
_defaults:
autowire: true
autoconfigure: true
public: false
# Bind all arguments requested by multiple services (auto-wiring)
bind:
$yourParameter: '%your.parameter%'
Put a parameter in this bind section allows you to inject it like a service in all other services (including controllers).
Then in your controllers and all other services, you could do something like this:
class RandomController extends Controller
{
private $yourParameter;
public function __construct(string $yourParameter)
{
$this->yourParameter = $yourParameter;
}
...
I answered your question about injecting parameters. Now if you want to use it in your route annotation, I would test something like this.
/**
* @Route("/api/{apiVersion}/the/rest/of/your/route", name="route_name", defaults={"apiVersion"="%yourParameter%"})
*/
public function yourAction()
{}
I didn't test this last solution. Don't know if it still work with symfony 4. If not maybe try to put %$yourParameter% (with a '$'). Tell me about that.
Edit:
Or even better for you situation (I assume that you are using the annotation routing): I guess your parameter is important only for the /api/ part of your application. Then you can define in your config/routes/annotations.yaml file all your controller concerned by your api. I suggest something like this.
controllers:
path: /api/{apiVersion}
resource: ../../src/Controller/Api
type: annotation
defaults:
apiVersion : '%your.parameter%'
# And maybe add also requirements like this
requirements:
apiVersion: 'v0|v1|v2'
Where all your api controllers are in the src/Controller/Api folder. Therefore, this solution allows you to define this configuration only once.