ServiceModel.Grpc.DesignTime
1.9.1
See the version list below for details.
dotnet add package ServiceModel.Grpc.DesignTime --version 1.9.1
NuGet\Install-Package ServiceModel.Grpc.DesignTime -Version 1.9.1
<PackageReference Include="ServiceModel.Grpc.DesignTime" Version="1.9.1" />
paket add ServiceModel.Grpc.DesignTime --version 1.9.1
#r "nuget: ServiceModel.Grpc.DesignTime, 1.9.1"
// Install ServiceModel.Grpc.DesignTime as a Cake Addin #addin nuget:?package=ServiceModel.Grpc.DesignTime&version=1.9.1 // Install ServiceModel.Grpc.DesignTime as a Cake Tool #tool nuget:?package=ServiceModel.Grpc.DesignTime&version=1.9.1
ServiceModel.Grpc.SelfHost
ServiceModel.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.DesignTime
is package with C# code generator for client and server-side assets.
Declare a service contract
A service contract is an interface decorated with the ServiceContract
attribute. Interface methods decorated with the OperationContract
attribute are treated as gRPC operations.
For example, following ICalculator
contract with unary Sum
operation and client streaming MultiplyBy
operation:
[ServiceContract]
public interface ICalculator
{
[OperationContract]
Task<long> Sum(long x, int y, int z, CancellationToken token = default);
[OperationContract]
ValueTask<(int Multiplier, IAsyncEnumerable<int> Values)> MultiplyBy(IAsyncEnumerable<int> values, int multiplier, CancellationToken token = default);
}
Configure code generator for client proxies
For source code generation create a placeholder - a static partial class, name doesn’t matter. Configure which proxies should be generated via ImportGrpcService
attribute.
[ImportGrpcService(typeof(ICalculator))]
internal static partial class MyGrpcServices
{
// generated code ...
public static IClientFactory AddCalculatorClient(this IClientFactory clientFactory, Action<ServiceModelGrpcClientOptions> configure = null) {}
}
Instruct ClientFactory
to use a proxy from generated code.
IClientFactory clientFactory = new ClientFactory();
// register generated proxy for ICalculator
clientFactory.AddCalculatorClient();
// create an instance
ICalculator calculator = clientFactory.CreateClient<ICalculator>(channel);
Configure code generator for server endpoints
Implement service.
internal sealed class Calculator : ICalculator
{
public Task<long> Sum(long x, int y, int z, CancellationToken token)
{
...
}
public ValueTask<(int Multiplier, IAsyncEnumerable<int> Values)> MultiplyBy(IAsyncEnumerable<int> values, int multiplier, CancellationToken token)
{
...
}
}
For source code generation create a placeholder - a static partial class, name doesn’t matter. Configure which endpoints should be generated via ExportGrpcService
attribute.
Generate code with extensions for ServiceModel.Grpc.AspNetCore.
[ExportGrpcService(typeof(Calculator), GenerateAspNetExtensions = true)]
internal static partial class MyGrpcServices
{
// generated code ...
public static IServiceCollection AddCalculatorOptions(this IServiceCollection services, Action<ServiceModelGrpcServiceOptions<Calculator>> configure) {}
// generated code ...
public static GrpcServiceEndpointConventionBuilder MapCalculator(this IEndpointRouteBuilder builder) {}
}
Instruct Grpc.AspNetCore.Server
to use a proxy from generated code.
var builder = WebApplication.CreateBuilder();
// optional configuration for Calculator endpoint
builder.Services.AddCalculatorOptions(options => { ... });
var app = builder.Build();
// bind generated Calculator endpoint
app.MapCalculator();
Generate code with extensions for ServiceModel.Grpc.SelfHost.
[ExportGrpcService(typeof(Calculator), GenerateSelfHostExtensions = true)]
internal static partial class MyGrpcServices
{
// generated code ...
public static Server.ServiceDefinitionCollection AddCalculator(this Server.ServiceDefinitionCollection services, Func<Calculator> serviceFactory, Action<ServiceModelGrpcServiceOptions> configure = default) {}
// generated code ...
public static Server.ServiceDefinitionCollection AddCalculator(this Server.ServiceDefinitionCollection services, Calculator service, Action<ServiceModelGrpcServiceOptions> configure = default) {}
}
Instruct Grpc.Core.Server
to use a proxy from generated code.
var server = new Grpc.Core.Server();
// bind generated Calculator endpoint with configuration
server.Services.AddCalculator(
() => new Calculator(),
options => { ... });
// or bind generated Calculator endpoint with default configuration
server.Services.AddCalculator(() => new Calculator());
Links
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- ServiceModel.Grpc (>= 1.9.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ServiceModel.Grpc.DesignTime:
Package | Downloads |
---|---|
ServiceModel.Grpc.MemoryPackMarshaller
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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.11.0 | 403 | 11/23/2024 |
1.10.1 | 2,762 | 10/19/2024 |
1.9.1 | 1,225 | 9/29/2024 |
1.9.0 | 3,674 | 7/21/2024 |
1.8.3 | 2,604 | 5/18/2024 |
1.8.2 | 1,046 | 3/2/2024 |
1.8.1 | 1,403 | 2/13/2024 |
1.8.0 | 200 | 1/7/2024 |
1.7.0 | 181 | 12/24/2023 |
1.6.1 | 287 | 11/25/2023 |
1.6.0 | 769 | 9/9/2023 |
1.5.2 | 1,143 | 6/25/2023 |
1.5.1 | 690 | 5/1/2023 |
1.5.0 | 415 | 3/7/2023 |
1.4.13 | 1,220 | 12/19/2022 |
1.4.12 | 434 | 11/19/2022 |
1.4.11 | 394 | 10/23/2022 |
1.4.10 | 1,658 | 8/14/2022 |
1.4.9 | 530 | 7/23/2022 |
1.4.8 | 535 | 5/29/2022 |
1.4.7 | 466 | 5/21/2022 |
1.4.6 | 509 | 4/3/2022 |
1.4.5 | 452 | 3/26/2022 |
1.4.4 | 433 | 3/12/2022 |
1.4.3 | 434 | 2/5/2022 |
1.4.2 | 19,360 | 1/22/2022 |
1.4.1 | 278 | 1/8/2022 |
1.4.0 | 2,448 | 11/26/2021 |
1.3.2 | 354 | 11/5/2021 |
1.3.1 | 451 | 10/10/2021 |
1.3.0 | 372 | 7/31/2021 |
1.2.1 | 376 | 6/12/2021 |
1.2.0 | 380 | 6/6/2021 |
1.1.9 | 335 | 5/8/2021 |
1.1.8 | 364 | 3/28/2021 |
1.1.7 | 415 | 1/3/2021 |
1.1.6 | 397 | 12/13/2020 |
1.1.5 | 400 | 11/21/2020 |
1.0.1 | 496 | 10/11/2020 |
1.0.0 | 607 | 9/13/2020 |
1.0.0-pre1 | 320 | 8/26/2020 |