Skip to content

[REQ][CSHARP] Make TokenProvider abstract method GetAsync protected for override #22601

@alec-petersen

Description

@alec-petersen

Is your feature request related to a problem? Please describe.

It seems users should be able to implement their own functionality for providing a token. The current implementation RateLimitProvider does not accomplish what I am looking for, I'm not going to have a list of tokens at the beginning of program execution, I'm going to need to fetch a token (if the one has expired) and then provide it to the caller

Describe the solution you'd like

This is the current code, I'd like to make the GetAsync public as well as move the ArgumentException thrown here in the constructor to the constructor of the RateLimitProvider class.

    /// <summary>
    /// A class which will provide tokens.
    /// </summary>
    public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
    {
        /// <summary>
        /// The array of tokens.
        /// </summary>
        protected TTokenBase[] _tokens;

        internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);

        /// <summary>
        /// Instantiates a TokenProvider.
        /// </summary>
        /// <param name="tokens"></param>
        public TokenProvider(IEnumerable<TTokenBase> tokens)
        {
            _tokens = tokens.ToArray();

            if (_tokens.Length == 0)
                throw new ArgumentException("You did not provide any tokens.");
        }
    }

Describe alternatives you've considered

I could put a new implementation in the generated code, but I still think it makes sense to have this behavior extendable by users without making the internals visible.

I am happy to do this work and open a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions