在运行时添加删除Kestrel Grpc服务。

问题描述 投票:0回答:0

问题:在启动后可以注册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。

有一种方法是使用单一的虚拟路由服务,然后持有服务的注册表和路由请求。然而,这需要修改合同,而且可能会重新发明适当的处理程序发现和路由的轮子。

c# asp.net-core grpc kestrel
© www.soinside.com 2019 - 2024. All rights reserved.