-
Book Overview & Buying
-
Table Of Contents
Building CLI Applications with C# and .NET
By :
Let’s register the sync command in the Program class. It’s only a matter of one line of code:
rootCommand.AddCommand(new SyncCommand(_clientFactory, _service, "sync", "sync local and remote bookmark stores"));
But wait! Where did the _clientFactory variable come from?!
Well done! You spotted it! 😊
As you may have guessed, this is a reference to the HttpClient that we need to configure to make the magic happen. This is where we will talk about the named clients approach that we mentioned earlier.
The _clientFactory variable is of type IHttpClientFactory. So, we first need to declare it within the Main method of the Program class:
IHttpClientFactory _clientFactory;
This will allow us later to retrieve a reference to it and pass it to the constructor of SyncCommand during its registration (as we saw earlier). We can retrieve that reference as follows:
_clientFactory = host.Services.GetRequiredService...