示例#1
0
        public OpenApiFactory(OpenApiOptions options, Func <HttpMessageHandler> httpMessageHandlerFactory, bool disposeHandler)
        {
            if (options.PortalUrl == null)
            {
                throw new ArgumentNullException($"{nameof(options)}.{nameof(options.PortalUrl)}");
            }
            if (string.IsNullOrEmpty(options.Token))
            {
                throw new ArgumentNullException($"{nameof(options)}.{nameof(options.Token)}");
            }

            var baseUri = new UriBuilder(options.PortalUrl)
            {
                Path = "/openapi/v1/"
            }.Uri;
            var token = options.Token;

            _httpClientFactory = () => new HttpClient(httpMessageHandlerFactory(), disposeHandler)
            {
                BaseAddress           = baseUri,
                DefaultRequestHeaders = { Authorization = new AuthenticationHeaderValue(token) },
                Timeout = TimeSpan.FromMilliseconds(options.Timeout)
            };
        }
示例#2
0
 public OpenApiFactory(OpenApiOptions options, Func <HttpMessageHandler> httpMessageHandlerFactory)
     : this(options, httpMessageHandlerFactory, true)
 {
 }
示例#3
0
 public OpenApiFactory(OpenApiOptions options) : this(options, () => Handler.Value, false)
 {
 }