Exemplo n.º 1
0
        /// <summary>
        /// Constructor for <see cref="PwnedPasswordService"/>.
        /// </summary>
        /// <param name="httpClient"><see cref="HttpClient"/> instance passed by DI injection</param>
        /// <param name="options"><see cref="IOptions{PwnedOptions}"/> instance passed by DI injection.</param>
        public PwnedPasswordService(
            HttpClient httpClient,
            IOptions <PwnedOptions> options)
        {
            Client   = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
            _options = options.Value;

            var userAgent = $"{nameof(PwnedPasswordService)}-kdcllc";

            if (!string.IsNullOrEmpty(_options?.UserAgent))
            {
                userAgent = _options?.UserAgent;
            }

            httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
            httpClient.DefaultRequestHeaders.Add("User-Agent", userAgent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for <see cref="PwnedBreachService"/>.
        /// </summary>
        /// <param name="httpClient"><see cref="HttpClient"/> instance passed by DI injection</param>
        /// <param name="options"><see cref="IOptions{PwnedOptions}"/> instance passed by DI injection.</param>
        public PwnedBreachService(
            HttpClient httpClient,
            IOptions <PwnedOptions> options)
        {
            _options = options.Value;

            Client = httpClient ?? throw new System.ArgumentNullException(nameof(httpClient));

            var userAgent = $"{nameof(PwnedBreachService)}-kdcllc";

            if (!string.IsNullOrEmpty(_options?.UserAgent))
            {
                userAgent = _options?.UserAgent;
            }

            httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
            httpClient.DefaultRequestHeaders.Add("User-Agent", userAgent);
            httpClient.DefaultRequestHeaders.Add("api-version", _options.ServiceApiVersion);
        }