It seems like Grpc.Net requires ASP.NET Core in order to host a service whereas Grpc.Core doesn't? What are the differences? Which one is preferred?
Grpc.Net
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
// Communication with gRPC endpoints must be made through a gRPC client.
// To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909
endpoints.MapGrpcService<GreeterService>();
});
}
Grpc.Core
Server server = new Server
{
Services = { RouteGuide.BindService(new RouteGuideImpl(features)) },
Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
};
server.Start();
Grpc.Core is a library that is based on the native implementation of gRPC. It is basically a binding to the native library that makes it possible to use “the original” gRPC directly for both client and server purposes.
Grpc.AspNetCore is a managed reimplementation for gRPC that is built on top of the Kestrel server stack. This makes Grpc.AspNetCore in general a lot more efficient compared to the native implementation. Being built for ASP.NET Core itself, it also integrates a lot more nicely into ASP.NET Core applications which also allows you to host gRPC services side-by-side with other ASP.NET Core endpoints. In contrast, it may not support all gRPC features and is also limited to the server-side aspect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With