30 lines
992 B
C#
30 lines
992 B
C#
using Store.Management.Api.Authentication;
|
|
using Store.Management.Api.Transport;
|
|
using Store.Management.Api.Users;
|
|
|
|
namespace Store.Management.Api;
|
|
|
|
/// <summary>一个服务地址与一个用户会话对应一个实例;在应用容器中注册为单例。</summary>
|
|
public sealed class StoreApiClient : IDisposable
|
|
{
|
|
public TokenSession Session { get; } = new();
|
|
public ApiTransport Transport { get; }
|
|
public IAuthApi Auth { get; }
|
|
public IUserApi Users { get; }
|
|
|
|
/// <param name="httpClient">可选的外部 HTTP 客户端,由调用方管理其生命周期。</param>
|
|
public StoreApiClient(ApiClientOptions options, HttpClient? httpClient = null)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(options);
|
|
Transport = new ApiTransport(options, Session, httpClient);
|
|
Auth = new AuthApi(Transport, Session);
|
|
Users = new UserApi(Transport);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Session.Clear();
|
|
Transport.Dispose();
|
|
}
|
|
}
|