Skip to content

Commit bfd1580

Browse files
author
yilei
committed
简化Server ChannelOption配制,统一在UseGrpcOptions配制
1 parent 8eb4bdc commit bfd1580

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/Grpc.Extension/Grpc.Extension.xml

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Grpc.Extension/Options/GrpcServerOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Grpc.Extension.Abstract.Model;
1+
using Grpc.Core;
2+
using Grpc.Extension.Abstract.Model;
23
using System;
34
using System.Collections.Generic;
45
using System.Text;
@@ -49,6 +50,11 @@ public int DefaultErrorCode
4950
get { return GrpcErrorCode.DefaultErrorCode; }
5051
set { GrpcErrorCode.DefaultErrorCode = value; }
5152
}
53+
54+
/// <summary>
55+
/// ChannelOption
56+
/// </summary>
57+
public IEnumerable<ChannelOption> ChannelOptions { get; set; }
5258
}
5359

5460
}

src/Grpc.Extension/ServerBuilder.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class ServerBuilder
2727
private readonly List<ServerInterceptor> _interceptors = new List<ServerInterceptor>();
2828
private readonly List<ServerServiceDefinition> _serviceDefinitions = new List<ServerServiceDefinition>();
2929
private readonly List<IGrpcService> _grpcServices = new List<IGrpcService>();
30-
private IEnumerable<ChannelOption> _channelOptions;
3130

3231
/// <summary>
3332
/// ServerBuilder
@@ -225,17 +224,6 @@ private void CheckUseJaeger()
225224
if (tracer != null) GlobalTracer.Register(tracer);
226225
}
227226

228-
/// <summary>
229-
/// 配制ChannelOptions
230-
/// </summary>
231-
/// <param name="channelOptions"></param>
232-
/// <returns></returns>
233-
public ServerBuilder UseChannelOptions(IEnumerable<ChannelOption> channelOptions)
234-
{
235-
_channelOptions = channelOptions;
236-
return this;
237-
}
238-
239227
/// <summary>
240228
/// 构建Server
241229
/// </summary>
@@ -246,7 +234,7 @@ public Server Build()
246234
if (string.IsNullOrWhiteSpace(GrpcServerOptions.Instance.ServiceAddress))
247235
throw new ArgumentException(@"GrpcServer:ServiceAddress is null");
248236

249-
Server server = new Server(_channelOptions);
237+
Server server = new Server(GrpcServerOptions.Instance.ChannelOptions);
250238
//使用拦截器
251239
var serviceDefinitions = ApplyInterceptor(_serviceDefinitions, _interceptors);
252240
//添加服务定义

0 commit comments

Comments
 (0)