Scenario:
Create a Sign on service to return list of users in out system. Register the gRPC client in the .NET core web app.Solution:
Add nuget package Grpc.Net.ClientFactory- In startup.cs, ConfigureServices method, register the service as below:
- In controller invoke the client as below:
1 2 3 4 | public void ConfigureServices(IServiceCollection services) { services.AddGrpcClient<SignOn.SignOnClient>(options => { options.Address = new Uri(ConfigurationManager.AppSetting["gRPC:url"]); }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | private readonly SignOn.SignOnClient _signOnClient; public HomeController(ILogger<HomeController> logger, SignOn.SignOnClient signOnClient) { _logger = logger; _signOnClient = signOnClient; } .. .. using (var call = _signOnClient.GetAllUsers(new UserRequest())) { ... |
No comments:
Post a Comment