3

我们想将我们的项目从 grpc.core 迁移到 gprc-dotnet。在我的 grpc 服务器中,我引用了包 Grpc.AspNetCore。proto 文件在不同的项目中编译并共享。当我实现我的服务器方法时:

**using Grpc.Core;**
using Sample.Shared;

namespace Sample.GrpcServer.Services;

public class CustomerService : CustomerGrpcService.CustomerGrpcServiceBase
{
    private readonly ILogger<CustomerService> _logger;
    public CustomerService(ILogger<CustomerService> logger)
    {
        _logger = logger;
    }

    public override Task<CustomerListResponse> GetCustomerList(CustomerListRequest request, ServerCallContext context)
    {
       ...
    }

ServerCallContext 类要求我导入要删除的 Grpc.Core。我应该如何使用 grpc-dotnet 来实现我的覆盖,例如 ServerCallContext 类?

看起来 ServerCallContext 是在包含命名空间 Grpc.Core 的包 Grpc.Core.Api 中实现的。这有点令人困惑,但可能是为了向后兼容而实现的。也许有人可以对此发表评论。因此,在这种情况下唯一真正要做的就是使用正确的 nuget 包 Grpc.AspNetCore.Server。对 Grpc.Core 的引用将从这个和底层引用的程序集中提取。

4

1 回答 1

0

Grpc.AspNetCorepackages 包含一个名称空间Grpc.Core,其中类似的类ServerCallContext也在已弃用的Grpc.Core包中。

我们删除了对已弃用包的Grpc.Core引用,并删除了对和的引用Google.ProtobufGrpc.Tools因为它们包含在Grpc.AspNetCore包中。

此链接提供有关 grpc 迁移的更多信息: https ://docs.microsoft.com/en-us/aspnet/core/grpc/migration?view=aspnetcore-6.0

于 2022-02-04T14:44:16.217 回答