Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Sep 19, 2023
1 parent aafaff5 commit 4d30f48
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ public static GrpcChannelx CreateChannel(this IGrpcChannelProvider provider, Grp
/// </summary>
public static class GrpcChannelProvider
{
private static IGrpcChannelProvider _defaultProvider;
static IGrpcChannelProvider defaultProvider;

/// <summary>
/// Gets a default channel provider. the provider will be initialized by <see cref="GrpcChannelProviderHost"/>.
/// </summary>
public static IGrpcChannelProvider Default
=> _defaultProvider ?? throw new InvalidOperationException("The default GrpcChannelProvider is not configured yet. Setup GrpcChannelProviderHost or initialize manually. ");
=> defaultProvider ?? throw new InvalidOperationException("The default GrpcChannelProvider is not configured yet. Setup GrpcChannelProviderHost or initialize manually. ");

public static void SetDefaultProvider(IGrpcChannelProvider provider)
{
_defaultProvider = provider;
defaultProvider = provider;
}
}

Expand All @@ -59,34 +59,34 @@ public static void SetDefaultProvider(IGrpcChannelProvider provider)
/// </summary>
public sealed class LoggingGrpcChannelProvider : IGrpcChannelProvider
{
private readonly IGrpcChannelProvider _baseProvider;
readonly IGrpcChannelProvider baseProvider;

public LoggingGrpcChannelProvider(IGrpcChannelProvider baseProvider)
{
_baseProvider = baseProvider ?? throw new ArgumentNullException(nameof(baseProvider));
this.baseProvider = baseProvider ?? throw new ArgumentNullException(nameof(baseProvider));
}

public GrpcChannelx CreateChannel(CreateGrpcChannelContext context)
{
var channel = _baseProvider.CreateChannel(context);
var channel = baseProvider.CreateChannel(context);
Debug.Log($"Channel Created: {context.Target.Host}:{context.Target.Port} ({(context.Target.IsInsecure ? "Insecure" : "Secure")}) [{channel.Id}]");
return channel;
}

public IReadOnlyCollection<GrpcChannelx> GetAllChannels()
{
return _baseProvider.GetAllChannels();
return baseProvider.GetAllChannels();
}

public void UnregisterChannel(GrpcChannelx channel)
{
_baseProvider.UnregisterChannel(channel);
baseProvider.UnregisterChannel(channel);
Debug.Log($"Channel Unregistered: {channel.TargetUri.Host}:{channel.TargetUri.Port} [{channel.Id}]");
}

public void ShutdownAllChannels()
{
_baseProvider.ShutdownAllChannels();
baseProvider.ShutdownAllChannels();
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ public DefaultGrpcChannelProvider(GrpcCCoreChannelOptions channelOptions) : base
/// </summary>
public class GrpcNetClientGrpcChannelProvider : GrpcChannelProviderBase
{
readonly Func<GrpcChannelOptions> _defaultChannelOptionsFactory;
readonly Func<GrpcChannelOptions> defaultChannelOptionsFactory;
public GrpcNetClientGrpcChannelProvider()
: this(new GrpcChannelOptions())
{
Expand All @@ -199,7 +199,7 @@ public GrpcNetClientGrpcChannelProvider(GrpcChannelOptions options)

public GrpcNetClientGrpcChannelProvider(Func<GrpcChannelOptions> optionsFactory)
{
_defaultChannelOptionsFactory = optionsFactory ?? throw new ArgumentNullException(nameof(optionsFactory));
defaultChannelOptionsFactory = optionsFactory ?? throw new ArgumentNullException(nameof(optionsFactory));
}

/// <summary>
Expand All @@ -208,7 +208,7 @@ public GrpcNetClientGrpcChannelProvider(Func<GrpcChannelOptions> optionsFactory)
protected override GrpcChannelx CreateChannelCore(int id, CreateGrpcChannelContext context)
{
var address = new Uri((context.Target.IsInsecure ? "http" : "https") + $"://{context.Target.Host}:{context.Target.Port}");
var channelOptions = context.ChannelOptions.Get<GrpcChannelOptions>() ?? _defaultChannelOptionsFactory();
var channelOptions = context.ChannelOptions.Get<GrpcChannelOptions>() ?? defaultChannelOptionsFactory();
var channel = GrpcChannel.ForAddress(address, channelOptions);
var channelHolder = new GrpcChannelx(
id,
Expand All @@ -229,7 +229,7 @@ protected override GrpcChannelx CreateChannelCore(int id, CreateGrpcChannelConte
/// </summary>
public class GrpcCCoreGrpcChannelProvider : GrpcChannelProviderBase
{
private readonly GrpcCCoreChannelOptions _defaultChannelOptions;
private readonly GrpcCCoreChannelOptions defaultChannelOptions;

public GrpcCCoreGrpcChannelProvider()
: this(new GrpcCCoreChannelOptions())
Expand All @@ -243,15 +243,15 @@ public GrpcCCoreGrpcChannelProvider(IReadOnlyList<ChannelOption> channelOptions)

public GrpcCCoreGrpcChannelProvider(GrpcCCoreChannelOptions channelOptions)
{
_defaultChannelOptions = channelOptions ?? throw new ArgumentNullException(nameof(channelOptions));
defaultChannelOptions = channelOptions ?? throw new ArgumentNullException(nameof(channelOptions));
}

/// <summary>
/// Create a channel to the target and register the channel under the management of the provider.
/// </summary>
protected override GrpcChannelx CreateChannelCore(int id, CreateGrpcChannelContext context)
{
var channelOptions = context.ChannelOptions.Get<GrpcCCoreChannelOptions>() ?? _defaultChannelOptions;
var channelOptions = context.ChannelOptions.Get<GrpcCCoreChannelOptions>() ?? defaultChannelOptions;
var channel = new Channel(context.Target.Host, context.Target.Port, context.Target.IsInsecure ? ChannelCredentials.Insecure : channelOptions.ChannelCredentials, channelOptions.ChannelOptions);
var channelHolder = new GrpcChannelx(
id,
Expand Down

0 comments on commit 4d30f48

Please sign in to comment.