Skip to content

Latest commit

 

History

History
85 lines (63 loc) · 2.87 KB

File metadata and controls

85 lines (63 loc) · 2.87 KB

ABP.GeoServerRest.HttpClient

目录概览

HttpClient 是整个 GeoServer REST 客户端模块的实现层,提供了所有 GeoServer REST API 的具体实现。它依赖于 HttpContracts 层的接口定义和模型,使用 IHttpClientFactory 管理 HTTP 连接。

职责:

  • 实现 IGeoServerHttpClient 接口(基于 IHttpClientFactory
  • 实现所有业务服务接口(约 34 个)
  • 配置 Named HttpClient(BaseAddress、Basic 认证、超时)
  • 提供模块初始化入口和配置扩展方法

上下游关系:

  • 上游:依赖 ABP.GeoServerRest.HttpContracts
  • 下游:ABP.GeoServerRest.HttpApi 依赖此模块

入口与调用

模块初始化

ABPGeoServerRestHttpClientModule.cs

ConfigureServices 中:

  1. 注册 Named HttpClient "GeoServerRestClient"
  2. IOptions<GeoServerRestClientOptions> 读取配置
  3. 设置 BaseAddress、超时、Accept 头
  4. 配置 Basic 认证头(用户名+密码 Base64 编码)

配置入口

// 在模块中调用
services.AddGeoServerRestClient(options =>
{
    options.BaseUrl = "http://localhost:8080/geoserver";
    options.Username = "admin";
    options.Password = "geoserver";
    options.TimeoutSeconds = 60;
});

使用示例

public class MyService
{
    private readonly IWorkspaceService _workspaceService;
    private readonly ILayerService _layerService;

    public MyService(IWorkspaceService workspaceService, ILayerService layerService)
    {
        _workspaceService = workspaceService;
        _layerService = layerService;
    }

    public async Task ListWorkspacesAsync()
    {
        var workspaces = await _workspaceService.GetWorkspacesAsync();
        foreach (var ws in workspaces)
        {
            Console.WriteLine(ws.Name);
        }
    }
}

文件说明

ABPGeoServerRestHttpClientModule.cs

ABP 模块类,依赖 ABPGeoServerRestHttpContractsModuleAbpLocalizationModule

  • PreConfigureServices:注册嵌入式虚拟文件系统和本地化资源
  • ConfigureServices:注册 Named HttpClient,配置 BaseAddress、认证、超时

GeoServerRestClientConfigurationExtensions.cs

扩展方法 AddGeoServerRestClient,接收 Action<GeoServerRestClientOptions> 委托配置选项。

子目录