ServiceAdaptor.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Microsoft.AspNetCore.Hosting;
  2. using Newtonsoft.Json.Linq;
  3. using ServiceAdaptor.NetCore.Client;
  4. using Vit.Core.Module.Log;
  5. using Vit.Extensions;
  6. namespace ServiceAdaptor.NetCore.MinHttp
  7. {
  8. public class ServiceAdaptor : IServiceAdaptor
  9. {
  10. public IWebHostBuilder InitWebHostBuilder(IWebHostBuilder builder, JObject config, out IApiClient apiClient)
  11. {
  12. #region (x.)构建ApiClient
  13. var httpApi = new ApiClient();
  14. apiClient = httpApi;
  15. #region (x.x.1)gatewayAddress
  16. var gatewayAddress = config["gatewayAddress"].ConvertToString();
  17. httpApi.vitHttpClient.BaseAddress = gatewayAddress;
  18. #endregion
  19. #region (x.x.2)超时时间
  20. var timeoutSeconds = config["timeoutSeconds"].ConvertBySerialize<int?>();
  21. if (timeoutSeconds.HasValue)
  22. {
  23. httpApi.vitHttpClient.TimeoutSeconds = timeoutSeconds.Value;
  24. }
  25. #endregion
  26. #endregion
  27. Logger.Info("[ServiceAdaptor.NetCore.MinHttp]配置:" + new { gatewayAddress }.Serialize());
  28. return builder;
  29. }
  30. }
  31. }