Database – How should I provide data for the service?

How should I correctly provide data to a service?

For example in submitForm() I am using the following code.

$this->session->set('var1', $name);
$this->session->set('var2', $count);

I have a service where I want to access the data from the session and save it in the database.

Should I read the data from the session in a controller and transfer it to the service via parameters? I think no.
My idea is to create a DTO:

  private $id;

  private $var1;

  private $var2;

  public function getVar1(): string
    return $this->var1;

  public function getVar2(): int
    return $this->var2;

Then pass the object to service and insert it into db.
But I don't know where to create the object with values ​​from the session (in the controller or in the service?).
I'm not a Drupal or Symfony developer – I'm just learning and looking for good practices.