Пример #1
0
        /// <summary>
        /// Registers the default <paramref name="baseAddress"/> (will automatically create the <see cref="HttpClient"/> on first use) and <paramref name="beforeRequest"/> for the specified .NET <paramref name="nameSpace"/>.
        /// </summary>
        /// <param name="nameSpace">The namespace.</param>
        /// <param name="baseAddress">Gets or sets the base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests.</param>
        /// <param name="beforeRequest">The <see cref="Action{HttpRequestMessage}"/> to invoke before the <see cref="HttpRequestMessage">Http Request</see> is made (see <see cref="WebApiServiceAgentBase.BeforeRequest"/>).</param>
        public static void Register(string nameSpace, Uri baseAddress, Action <HttpRequestMessage> beforeRequest = null)
        {
            if (string.IsNullOrEmpty(nameSpace))
            {
                throw new ArgumentNullException(nameof(nameSpace));
            }

            if (baseAddress == null)
            {
                throw new ArgumentNullException(nameof(baseAddress));
            }

            lock (_lock)
            {
                _dict[nameSpace] = new WebApiServiceAgentRegisteredData {
                    BaseAddress = baseAddress, BeforeRequest = beforeRequest
                };
            }
        }
Пример #2
0
        /// <summary>
        /// Registers the default <paramref name="client"/> and <paramref name="beforeRequest"/> for the specified .NET <paramref name="nameSpace"/>.
        /// </summary>
        /// <param name="nameSpace">The namespace.</param>
        /// <param name="client">The <see cref="HttpClient"/>.</param>
        /// <param name="beforeRequest">The <see cref="Action{HttpRequestMessage}"/> to invoke before the <see cref="HttpRequestMessage">Http Request</see> is made (see <see cref="WebApiServiceAgentBase.BeforeRequest"/>).</param>
        public static void Register(string nameSpace, HttpClient client, Action <HttpRequestMessage> beforeRequest = null)
        {
            if (string.IsNullOrEmpty(nameSpace))
            {
                throw new ArgumentNullException(nameof(nameSpace));
            }

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            lock (_lock)
            {
                _dict[nameSpace] = new WebApiServiceAgentRegisteredData {
                    Client = client, BeforeRequest = beforeRequest
                };
            }
        }