Creating service contracts
First, we need to add the Grpc.AspNetCore
NuGet package to the Codebreaker.Live
project. Then, we must add a Protobuf file as a contract to the service. The contract file is language and platform-independent, so a .NET service can communicate with a Dart application using the same Protobuf file.
Using Visual Studio, add a Protos
folder, and use the Visual Studio template to create a Protobuf file. When using the command line, with the current directory set to the project folder of Codebreaker.Live
, you can run the following command to create the LiveGame.proto
file inside the Protos
folder:
dotnet new proto -o Protos -n LiveGame
Now, let’s create contracts for both live-service
and game-apis
.
Creating a gRPC service contract for live-service
The simpler contract is the one for live-service
:
Codebreaker.Live/Protos/LiveGame.proto
syntax = "proto3"; option csharp_namespace = "Codebreaker.Live.Grpc"; package ReportGame...