42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
using Grpc.Net.Client;
|
|
using MxGateway.Contracts.Proto;
|
|
|
|
namespace MxGateway.Client;
|
|
|
|
/// <summary>
|
|
/// Provides the initial .NET client entry point and raw generated gRPC client.
|
|
/// </summary>
|
|
public sealed class MxGatewayClient : IAsyncDisposable
|
|
{
|
|
private readonly GrpcChannel _channel;
|
|
|
|
private MxGatewayClient(GrpcChannel channel)
|
|
{
|
|
_channel = channel;
|
|
RawClient = new MxAccessGateway.MxAccessGatewayClient(channel);
|
|
}
|
|
|
|
public MxAccessGateway.MxAccessGatewayClient RawClient { get; }
|
|
|
|
public static MxGatewayClient Create(MxGatewayClientOptions options)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(options);
|
|
options.Validate();
|
|
|
|
var channel = GrpcChannel.ForAddress(
|
|
options.Endpoint,
|
|
new GrpcChannelOptions
|
|
{
|
|
LoggerFactory = options.LoggerFactory,
|
|
});
|
|
|
|
return new MxGatewayClient(channel);
|
|
}
|
|
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
_channel.Dispose();
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|