Library that enables applications to communicate with gRPC services using code-first approach, helps to get around some limitations of gRPC protocol. Provides exception handling. Helps to migrate existing WCF solution to gRPC with minimum effort.
$ dotnet add package ServiceModel.Grpc.MemoryPackMarshallerServiceModel.Grpc enables applications to communicate with gRPC services using a code-first approach (no .proto files), helps to get around limitations of gRPC protocol like "only reference types", "exact one input", "no nulls", "no value-types". Provides exception handling. Helps to migrate existing WCF solution to gRPC with minimum effort.
ServiceModel.Grpc.MemoryPackMarshaller is package with IMarshallerFactory implementation, based on MemoryPack serializer.
Instruct ClientFactory to use MemoryPackMarshallerFactory as default marshaller for all clients.
IClientFactory defaultClientFactory
= new ClientFactory(new ServiceModelGrpcClientOptions
{
// set MemoryPackMarshaller as default Marshaller
MarshallerFactory = MemoryPackMarshallerFactory.Default
});
Instruct ClientFactory to use MemoryPackMarshallerFactory for concrete client.
// client factory with default (DataContractMarshallerFactory) marshaller
IClientFactory defaultClientFactory = new ClientFactory();
// set MemoryPackMarshaller only for ICalculator client
defaultClientFactory.AddClient<ICalculator>(options =>
{
options.MarshallerFactory = MemoryPackMarshallerFactory.Default;
});
Instruct ServiceModel.Grpc code-first to use MemoryPackMarshallerFactory as default marshaller for all endpoints.
var builder = WebApplication.CreateBuilder();
// enable ServiceModel.Grpc code-first
builder.Services.AddServiceModelGrpc(options =>
{
// set MemoryPackMarshaller as default Marshaller
options.DefaultMarshallerFactory = MemoryPackMarshallerFactory.Default;
});
Instruct ServiceModel.Grpc code-first to use MemoryPackMarshallerFactory for concrete endpoint.
var builder = WebApplication.CreateBuilder();
// enable ServiceModel.Grpc code-first with default (DataContractMarshallerFactory) marshaller
builder.Services.AddServiceModelGrpc();
// set MemoryPackMarshaller only for Calculator endpoint
builder.Services.AddServiceModelGrpcServiceOptions<Calculator>(options =>
{
options.MarshallerFactory = MemoryPackMarshallerFactory.Default;
});
Instruct ServiceModel.Grpc code-first to use MemoryPackMarshallerFactory.
var server = new Grpc.Core.Server();
// set MemoryPackMarshaller for Calculator endpoint
server.Services.AddServiceModelTransient(
()=> new Calculator(),
options =>
{
options.MarshallerFactory = MemoryPackMarshallerFactory.Default;
});