Skip to content

Commit

Permalink
(#140) paralax grpc: [pack-all-force]
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Oct 30, 2024
1 parent 4026f02 commit 9596b28
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Paralax.gRPC/src/Paralax.gRPC/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Diagnostics;
using Microsoft.Extensions.Options;

namespace Paralax.gRPC.Extensions
namespace Paralax.gRPC
{
public static class GrpcExtensions
{
Expand All @@ -25,8 +25,8 @@ public static IParalaxBuilder AddGrpc(this IParalaxBuilder builder, IConfigurati
{
var optionsBuilder = new GrpcOptionsBuilder();
configureOptions.Invoke(optionsBuilder);
var grpcOptions = optionsBuilder.Build();
builder.Services.AddSingleton(grpcOptions);
var grpcOptionsBuilt = optionsBuilder.Build();
builder.Services.AddSingleton(grpcOptionsBuilt);
}

builder.Services.AddCommonProtobufServices();
Expand All @@ -35,11 +35,11 @@ public static IParalaxBuilder AddGrpc(this IParalaxBuilder builder, IConfigurati
builder.Services.AddSingleton<CpuUsageService>();
builder.Services.AddSingleton<MemoryUsageService>();

var serviceProvider = builder.Services.BuildServiceProvider();
var grpcOptions = serviceProvider.GetRequiredService<IOptions<GrpcOptions>>().Value;

builder.Services.Configure<KestrelServerOptions>(options =>
{
var serviceProvider = builder.Services.BuildServiceProvider();
var grpcOptions = serviceProvider.GetRequiredService<IOptions<GrpcOptions>>().Value;

options.ListenAnyIP(grpcOptions.Port, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
Expand All @@ -48,11 +48,15 @@ public static IParalaxBuilder AddGrpc(this IParalaxBuilder builder, IConfigurati

builder.Services.AddGrpc(options =>
{
var grpcOptions = builder.Services.BuildServiceProvider().GetRequiredService<IOptions<GrpcOptions>>().Value;
options.MaxReceiveMessageSize = grpcOptions.MaxReceiveMessageSize;
options.MaxSendMessageSize = grpcOptions.MaxSendMessageSize;
});

if (grpcOptions.EnableReflection)
{
builder.Services.AddGrpcReflection();
}

return builder;
}

Expand Down

0 comments on commit 9596b28

Please sign in to comment.