- The standard way to inject services in other services is passing dependencies directly through the constructor:
mymodule.services.yml:
services:
mymodule.foo_service:
class: Drupal\mymodule\FooService
arguments: ['@current_user']
While you can define a factory method in *.services.yml, see https://symfony.com/doc/current/service_container/factories.html, in Drupal the most common places for this are Controllers and Plugins which implement ContainerInjectionInterface::create or ContainerFactoryPluginInterface::create. See How do I use dependency injection on \Drupal::moduleHandler() to a Controller?
\Drupal::service...
is largely used from procedural code when not in an OOP context, like hooks areor static callbacks. See the comment from @Kevin.