public TcpClient(IServiceProvider serviceProvider, ITcpClientSessionManager sessionManager, ILogger <TcpClient> logger, IOptions <GatewayConfiguration> configuration) { this.logger = logger; this.sessionManager = sessionManager; this.configuration = configuration.Value; eventLoopGroup = new MultithreadEventLoopGroup(); bootstrap = new Bootstrap().Group(eventLoopGroup) .Channel <TcpSocketChannel>() .Option(ChannelOption.TcpNodelay, true) .Option(ChannelOption.ConnectTimeout, TimeSpan.FromSeconds(30)) .Handler(new ActionChannelInitializer <ISocketChannel>(channel => { var scope = serviceProvider.CreateScope().ServiceProvider; IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast(new IdleStateHandler(this.configuration.BrabchServerReaderIdleTimeSeconds, this.configuration.BrabchServerWriterIdleTimeSeconds, this.configuration.BrabchServerAllIdleTimeSeconds)); pipeline.AddLast(scope.GetRequiredService <TcpMetadataDecoder>()); pipeline.AddLast(scope.GetRequiredService <TcpMetadataEncoder>()); pipeline.AddLast(scope.GetRequiredService <TcpClientHandler>()); })); }