Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Grpc.Net.Server for Hosting gRPC Servers in .NET Standard and .NET 8+ (Non-ASP.NET Core) #2543

Open
perpetualintelligencegit opened this issue Sep 24, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@perpetualintelligencegit

Proposal: Add Grpc.Net.Server for Non-ASP.NET Core Environments

Context

We have received customer requests to support gRPC within our terminal framework (for .NET Standard, .NET
https://github.com/perpetualintelligence/terminal
perpetualintelligence/terminal#44

Summary

Currently, gRPC server functionality is supported by:

  1. Grpc.AspNetCore: Designed for ASP.NET Core environments.
  2. Grpc.Core: Used for non-ASP.NET Core applications but is being deprecated.

With no clear alternative for non-ASP.NET Core environments like desktop, console, or lightweight server applications, developers are left without an option for gRPC servers outside of web contexts. This creates a gap for building gRPC servers in non-web scenarios.

Justification

  • Non-Web Use Cases: gRPC is widely used in desktop apps, console apps, IoT, microservices, and secured factory environments where ASP.NET Core adds unnecessary overhead.
  • No Alternative to Grpc.Core: As Grpc.Core is deprecated, developers need replacement that fits non-web applications.
  • Consistency with Grpc.Net.Client: A Grpc.Net.Server package would align with Grpc.Net.Client, providing a unified experience for non-web gRPC development.
  • Avoiding ASP.NET Core: Non-web applications shouldn’t need ASP.NET Core to host a gRPC server.

Proposed Solution

Introduce Grpc.Net.Server with:

  • Lightweight, dependency-free gRPC server support for non-web applications (Multi target .NET Standard 2.0, .NET Standard 2.1, .NET Standard 8.0+)
  • Full compatibility with Grpc.Net.Client.
  • Support for HTTP/2, SSL/TLS, and .NET 6, 7, and 8.
  • Grpc.AspNetCore will use Grpc.Net.Server

This would allow developers to easily adopt gRPC in non-ASP.NET Core environments without using deprecated packages.

@perpetualintelligencegit perpetualintelligencegit added the bug Something isn't working label Sep 24, 2024
@JamesNK
Copy link
Member

JamesNK commented Sep 24, 2024

What is a non-ASP.NET Core environment to you? You can host a gRPC service inside all kinds of apps. See #1419 (comment)

ASP.NET Core is just some APIs that you can include many kinds of .NET projects. All you need to do to support a gRPC server is add this line to a .NET 5+ app:

<FrameworkReference Include="Microsoft.AspNetCore.App" />

Creating a new server (TCP, TLS, HTTP/2, HTTP abstractions, etc) will be hundreds of hours of work, and the end result will be something done badly. It will be slower, less secure and have less features than Kestrel because it will have a fraction of the development time.

You or someone else is welcome to attempt writing your own server from scratch. I'd strongly advise against it, HTTP/2 is a very complicated protocol and it is easy to create DDOS vulnrabilities.

I can say with a lot of certainity that it won't be done as part of this project.

@perpetualintelligencegit
Copy link
Author

Thank you for the response. I understand the value of Kestrel and ASP.NET Core for hosting gRPC services, but that is for the end application. I don’t believe a class library should require a reference to Microsoft.AspNetCore.App.

Requiring Microsoft.AspNetCore.App introduces unnecessary overhead for projects that don’t need web server features, such as desktop apps, console apps, on-prem IoT, and microservices. A lightweight, modular gRPC server class library without this dependency would simplify development and allow broader reuse in different environments.

E.g. Our entire terminal framework that provides multiple network protocols is a class library (Non ASP.NET) clients can use in console, Blazor or web apps.

@JamesNK
Copy link
Member

JamesNK commented Sep 26, 2024

Everything I said earlier still stands. Creating a new HTTP server, with TCP, HTTP/2, TLS/SSL, logging, configuration, security hardening, performance testing, and so on is a HUGE amount of work. I can say with a lot of certainity that it won't be done as part of this project.

You're welcome to do it yourself. The .NET gRPC APIs to do so are public and can be layered on top of a new server. But like I said before, I strongly recommend against it.

@perpetualintelligencegit
Copy link
Author

perpetualintelligencegit commented Oct 12, 2024

@JamesNK: Thank you so much for your feedback. Based on your recommendation, we have successfully integrated the new gRPC setup into our Cross-Platform Terminal framework. Our implementation now consists of a class library (OneImlx.Terminal) that isolates the gRPC proto configuration and terminal routers, alongside an ASP.NET Core application that sets up the gRPC server, and a client library that facilitates the client apps.

We would greatly appreciate if you could review these files before we proceed with our release, and let us know if you see any concern:

The sample code demonstrates the multi-network protocol support (e.g. Udp, TCP, gRPC, HTTP) capabilities provided by the Terminal framework. https://github.com/perpetualintelligence/terminal/tree/main/apps/s2s

Thanks again for your feedback.

@HppZ
Copy link

HppZ commented Oct 24, 2024

I support this proposal!

@HppZ
Copy link

HppZ commented Oct 24, 2024

#1419

@HppZ
Copy link

HppZ commented Oct 25, 2024

Thank you for the response. I understand the value of Kestrel and ASP.NET Core for hosting gRPC services, but that is for the end application. I don’t believe a class library should require a reference to Microsoft.AspNetCore.App.

Requiring Microsoft.AspNetCore.App introduces unnecessary overhead for projects that don’t need web server features, such as desktop apps, console apps, on-prem IoT, and microservices. A lightweight, modular gRPC server class library without this dependency would simplify development and allow broader reuse in different environments.

E.g. Our entire terminal framework that provides multiple network protocols is a class library (Non ASP.NET) clients can use in console, Blazor or web apps.

Agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants