.NET Core gRPC

.NET Core ❤ gRPC

Posted on Monday, September 23, 2019 by Sourabh Shirhatti

This is a guest post by Sourabh Shirhatti, a Program Manger on the .NET team at Microsoft.

The .NET team at Microsoft has been working in close collaboration with the gRPC team since November 2018 on a new fully managed implementation of gRPC for .NET Core.

We’re pleased to announce that grpc-dotnet is now available with .NET Core 3.0 today!

How to get it?

grpc-dotnet packages have just been released to NuGet.org and are already available for use in your projects. These packages also require the latest .NET Core 3.0 shared framework. You can download the .NET Core 3.0 SDK for your dev machine and build servers from the .NET Core 3.0 download page to acquire the shared framework.

Getting Started

As gRPC is now a first-class citizen in .NET ecosystem, gRPC templates are included as part of the .NET SDK. To get started, navigate to a console window after installing the SDK and run the following commands.

dotnet new grpc -o GrpcGreeter cd GrpcGreeter dotnet run

To create a gRPC client and test with the newly created gRPC Greeter service, you can follow the rest of this tutorial here.

Doesn’t gRPC already work with .NET Core?

There are currently two official implementations of gRPC for .NET:

  • Grpc.Core: The original gRPC C# implementation based on the native gRPC Core library.
  • grpc-dotnet: The new implementation written entirely in C# with no native dependencies and based on the newly released .NET Core 3.0.

The implementations coexist side-by-side and each has its own advantages in terms of available features, integrations, supported platforms, maturity level and performance. Both implementations share the same API for invoking and handling RPCs, thus limiting the lock-in and enabling users to choose the implementation that satisfies their needs the best.

What’s new?

Unlike the existing C-Core based implementation (Grpc.Core), the new libraries (grpc-dotnet) make use of the existing networking primitives in the .NET Core Base Class Libraries (BCL). The diagram below highlights the difference between the existing Grpc.Core library and the new grpc-dotnet libraries.

gRPC .NET Stack

On the server side, the Grpc.AspNetCore.Server package integrates into ASP.NET Core, allowing developers to benefit from ecosystem of common cross-cutting concerns of logging, configuration, dependency injection, authentication, authorization etc. which have already been solved by ASP.NET Core. Popular libraries in the ASP.NET ecosystem such as Entity Framework Core (ORM), Serilog (Logging library), and Identity Server among others now work seamlessly with gRPC.

On the client side, the Grpc.Net.Client package builds upon the familiar HttpClient API that ships as part of .NET Core. As with the server, gRPC clients greatly benefit from the ecosystem of packages that build upon HttpClient. It is now possible to use existing packages such as Polly(Resilience and fault-handling library) and HttpClientFactory(manage HTTPClient lifetimes) with gRPC clients.

The diagram below captures the exhaustive list of all new .NET packages for gRPC and their relationship with the existing packages.

grpc-dotnet packages

In addition to the newly published packages that ship as part of grpc-dotnet, we’ve also made improvements that benefit both stacks. Visual Studio 2019 ships with language grammar support for protobuf files and automatic generation of gRPC server/client code upon saving a protobuf file without requiring full project rebuilds due to design-time builds.

gRPC in Visual Studio 2019

Feedback

We’re were excited about improving the gRPC experience for .NET developers. Please give it a try and let us about any feature ideas or bugs you may encounter at the grpc-dotnet issue tracker.



from Hacker News https://ift.tt/2kBCg9L