Code first gRPC client generation problem in ASP.NET

142 views Asked by At

I have followed this microsoft tutorial to create gRPC service and client. Now i have problem with generating gRPC client class.

To get data i use this method, but i doesn't seem right. I wish I could inject client using AddGrpcClient but i can't find any generated client gRPC classes.

using var channel = GrpcChannel.ForAddress("http://localhost:5053");
var client = channel.CreateGrpcService<IFullProjectInfoService>();

var reply = await client.GetFullProjectInfoAsync(
    new FullProjectInfoRequest { ProjectId = 1, UserId = 1 }
);
1

There are 1 answers

0
dan-kli On

To inject the client using dependency injection, you could use the AddCodeFirstGrpcClient function, as it is documented in the Register client service section of protobuf.net.

For your example it would look something like:

services.AddCodeFirstGrpcClient<IFullProjectInfoService>(o =>
{
    o.Address = new Uri("http://localhost:5053");
});