Dependency Injection and the Url object
You can inject the UrlGenerator as service and use UrlGenerator::generateFromRoute, but in the linked doc you are discouraged to do so:


  @internal Should not be used in user code. Use \Drupal\Core\Url
  instead.


So the code in your question to create an url object is OK for a service, but not the toString() method. Render the url only with this method when the page rendering process has started, for example in a theme. 

In a service you usually don't know this and you should return an unrendered url object, so that it can be rendered later in the rendering pipeline.

$url = Url::fromRoute('&lt;current&gt;', [], ['absolute' =&gt; 'true']);


toString() in the wrong place generates ugly error messages about early rendering which are hard to debug when this happens somewhere in a service.