Repository: dotnet/efcore
File: src/EFCore.Cosmos/Storage/Internal/SingletonCosmosClientWrapper.cs (C#)

Code before:
        }

        if (options.MaxRequestsPerTcpConnection != null)
        {
            configuration.MaxRequestsPerTcpConnection = options.MaxRequestsPerTcpConnection.Value;
        }

        if (options.HttpClientFactory != null)
        {
            configuration.HttpClientFactory = options.HttpClientFactory;
        }

        _options = configuration;
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual CosmosClient Client
        => NonCapturingLazyInitializer.EnsureInitialized(ref _client, this, CreateClient);

    private static CosmosClient CreateClient(SingletonCosmosClientWrapper wrapper)
        => string.IsNullOrEmpty(wrapper._connectionString)
            ? wrapper._tokenCredential == null
                ? wrapper._endpoint == null
                    ? throw new InvalidOperationException(CosmosStrings.ConnectionInfoMissing)
                    : new CosmosClient(wrapper._endpoint, wrapper._key, wrapper._options)
                : new CosmosClient(wrapper._endpoint, wrapper._tokenCredential, wrapper._options)
            : new CosmosClient(wrapper._connectionString, wrapper._options);

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual void Dispose()
    {
        _client?.Dispose();
        _client = null;
    }
}


Review comment (refactor):
nit: it may be off-brand, but these nested conditionals seem needlessly complicated - a few simple ifs would probably simplify.

Code after:
        }

        _client = options switch
        {
            { ConnectionString: not null and not "" } => new CosmosClient(options.ConnectionString, configuration),
            { TokenCredential: not null } => new CosmosClient(options.AccountEndpoint, options.TokenCredential, configuration),
            { AccountEndpoint: not null } => new CosmosClient(options.AccountEndpoint, options.AccountKey, configuration),
            _ => throw new InvalidOperationException(CosmosStrings.ConnectionInfoMissing)
        };
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual CosmosClient Client => _client;

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual void Dispose()
    {
        _client.Dispose();
    }
}