public async Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("Starting synchronizer service..."); if (_syncClient == null && _clientScope == null) { _clientScope = _dependencyScope.BeginLifetimeScope( containerConfig => _syncClientFactory.ConfigureContainerBuilder(containerConfig)); // The scope is disposed right after creation of the sync client. This should not be a problem as // the client holds references to all required instances after creation. _syncClient = _syncClientFactory.CreateSyncClient(_clientScope); var authenticator = _clientScope.Resolve <ISmintIoAuthenticator>(); Debug.Assert(authenticator != null, nameof(authenticator) + " != null"); // we have a system browser based authenticator here, which will work synchronously await authenticator.InitializeAuthenticationAsync(); } await _syncClient.StartAsync(cancellationToken); _logger.LogInformation("Started synchronizer service"); }