ServiceModel.Grpc

Code-first for gRPC

View on GitHub

ServiceModel.Grpc Grpc.Core server configuration

AddService…

var server = new Grpc.Core.Server();

server.Services.AddServiceModelSingleton(
    new MyService(),
    options =>
    {
        // service configuration
        options.MarshallerFactory  = ...
        options.ErrorHandler  = ...
        options.ServiceProvider  = ...
        options.Filters ...
    });

server.Services.AddServiceModelTransient(
    () => new MyService(),
    options =>
    {
        // service configuration
        options.MarshallerFactory  = ...
        options.ErrorHandler  = ...
        options.ServiceProvider  = ...
        options.Filters ...
    });

// register MyService in serviceProvider
IServiceProvider serviceProvider = ...;

server.Services.AddServiceModel<MyService>(
    serviceProvider,
    options =>
    {
        // service configuration
        options.MarshallerFactory  = ...
        options.ErrorHandler  = ...
        options.ServiceProvider  = ...
        options.Filters ...
    });

ServiceModelGrpcServiceOptions

Silent proxy generation (Reflection.Emit)

In this example

[ServiceContract]
public interface IContract
{
    [OperationContract]
    Task<T> SumAsync<T>(T x, T y);

    void Dispose();
}

internal sealed class Service : IContract { }

SumAsync and Dispose will be ignored during the service binding, use ServiceModelGrpcServiceOptions.ILogger to see warnings.