问题:在启动后可以注册degister grpc服务吗?是否可以在启动后再注册grpc服务?
以下是注册grpc服务的传统方法。
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterErvice>();
});
}
}
取自于著名的grpc.net项目示例。源,例如。https:/github.comgrpcgrpc-dotnetblobmasterexamplesGreeterServerStartup.cs。 或 https:/docs.microsoft.comen-usaspnetcoregrpc?view=aspnetcore-3.1。
有一种方法是使用单一的虚拟路由服务,然后持有服务的注册表和路由请求。然而,这需要修改合同,而且可能会重新发明适当的处理程序发现和路由的轮子。