public function createUserService()
    {
        $config = $this->container->get('cca.legacy_dic.contao_config');
        // Work around the fact that \Contao\Database::getInstance() always creates an instance,
        // even when no driver is configured (Database and Config are being imported into the user class and there-
        // fore causing an fatal error).
        if (!$config->get('dbDatabase')) {
            throw new \RuntimeException('Contao Database is not properly configured.');
        }

        $matcher = $this->container->get('contao.routing.scope_matcher');
        $request = $this->container->get('request_stack')->getCurrentRequest();

        // NULL request => CLI mode.
        if ((null === $request) || $matcher->isBackendRequest($request)) {
            return $this->container->get('contao.framework')->createInstance(BackendUser::class);
        }

        if ($matcher->isFrontendRequest($request)) {
            return $this->container->get('contao.framework')->createInstance(FrontendUser::class);
        }

        throw new \RuntimeException('Unknown TL_MODE encountered', 1);
    }