我需要为类似于 C# 中的接口的一组原型文件制定通用合同。 grpc 中有什么东西可以用来实现这样的功能吗?
interface IMyInterfaceWithCommonMethods
{
void MyCommonMethod1();
void MyCommonMethod2();
}
interface IMyInterface2: IMyInterfaceWithCommonMethods
{
void MyMethod2();
}
public class MyClass : IMyInterface2
{
public void MyMethod2()
{
Console.WriteLine("MyMethod2");
}
public void MyCommonMethod1()
{
throw new NotImplementedException();
}
public void MyCommonMethod2()
{
throw new NotImplementedException();
}
}
grpc 原型中的预期代码
service Myervice implements IMyInterfaceWithCommonMethods{
rpc MyCommonMethod1(MyRequest1) returns (MyResponse1);
rpc MyCommonMethod2(MyRequest1) returns (MyResponse1);
rpc MyMethod2(MyRequest1) returns MyResponse1;
}
没有。
我明白为什么这是可取的。
我不知道为什么它不是协议缓冲区的设施,也许:
Service
定义可以像接口一样发挥作用,请参阅健康检查作为替代方案,您可以将其作为组织最佳实践并在代码审查期间强制执行。