Skip to content

Commit

Permalink
简化Server ChannelOption配制,统一在UseGrpcOptions配制
Browse files Browse the repository at this point in the history
  • Loading branch information
yilei committed Sep 1, 2019
1 parent 8eb4bdc commit bfd1580
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
12 changes: 5 additions & 7 deletions src/Grpc.Extension/Grpc.Extension.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/Grpc.Extension/Options/GrpcServerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Grpc.Extension.Abstract.Model;
using Grpc.Core;
using Grpc.Extension.Abstract.Model;
using System;
using System.Collections.Generic;
using System.Text;
Expand Down Expand Up @@ -49,6 +50,11 @@ public int DefaultErrorCode
get { return GrpcErrorCode.DefaultErrorCode; }
set { GrpcErrorCode.DefaultErrorCode = value; }
}

/// <summary>
/// ChannelOption
/// </summary>
public IEnumerable<ChannelOption> ChannelOptions { get; set; }
}

}
14 changes: 1 addition & 13 deletions src/Grpc.Extension/ServerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class ServerBuilder
private readonly List<ServerInterceptor> _interceptors = new List<ServerInterceptor>();
private readonly List<ServerServiceDefinition> _serviceDefinitions = new List<ServerServiceDefinition>();
private readonly List<IGrpcService> _grpcServices = new List<IGrpcService>();
private IEnumerable<ChannelOption> _channelOptions;

/// <summary>
/// ServerBuilder
Expand Down Expand Up @@ -225,17 +224,6 @@ private void CheckUseJaeger()
if (tracer != null) GlobalTracer.Register(tracer);
}

/// <summary>
/// 配制ChannelOptions
/// </summary>
/// <param name="channelOptions"></param>
/// <returns></returns>
public ServerBuilder UseChannelOptions(IEnumerable<ChannelOption> channelOptions)
{
_channelOptions = channelOptions;
return this;
}

/// <summary>
/// 构建Server
/// </summary>
Expand All @@ -246,7 +234,7 @@ public Server Build()
if (string.IsNullOrWhiteSpace(GrpcServerOptions.Instance.ServiceAddress))
throw new ArgumentException(@"GrpcServer:ServiceAddress is null");

Server server = new Server(_channelOptions);
Server server = new Server(GrpcServerOptions.Instance.ChannelOptions);
//使用拦截器
var serviceDefinitions = ApplyInterceptor(_serviceDefinitions, _interceptors);
//添加服务定义
Expand Down

0 comments on commit bfd1580

Please sign in to comment.