You should install Relewise.Client.Extensions using NuGet:
Install-Package Relewise.Client.Extensions
Run this command from the NuGet Package Manager Console to install the NuGet package.
We provide a lot of ways to easily add the clients you need. The default way to do that is using the following code:
services.AddRelewise(options =>
{
options.DatasetId = Guid.Parse("1B5A09DB-561E-47E0-B8ED-4E559A1B7EB9");
options.ApiKey = "r4FqfMqtiZjJmoN";
options.Timeout = TimeSpan.FromSeconds(3);
});
This will wire up the client instances of ITracker
, IRecommender
and ISearcher
, and these clients will all be configured for the DatasetId
and ApiKey
options specificed above, and with a request timeout of 3 seconds.
Optionally, it is possible to define a ServerUrl
for the client to target. If no value is provided the client will by default target the main Relewise server.
We recommend that the DatasetId
, ApiKey
and ServerUrl
are stored in a configuration-file. We provide a default way of reading from the appsettings.json, see options.ReadFromConfiguration(configuration)
below:
IConfiguration configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"}.json", true)
.Build();
services.AddRelewise(options => options.ReadFromConfiguration(configuration));
The configuration offers a lot of other great features, such as
- Set specific options for
DatasetId
,ApiKey
,ServerUrl
andTimeout
for the individual client instances ofITracker
,IRecommender
andISearcher
. - Named clients to allow different configuration for integrations etc or to use for a multi site-setup.
Here is a full example of all the configuration settings we provide via the appsettings or via the fluent API:
"Relewise": {
"DatasetId": "<<dataset-id>>",
"ApiKey": "<<api-key>>",
"Timeout": "00:00:03",
"ServerUrl": "<<server-url>>",
"Tracker": {
"Timeout": "00:00:10"
},
"Recommender": {
"Timeout": "00:00:05"
},
"Searcher": {
"Timeout": "00:00:10"
},
"Named": {
"Integration": {
"Tracker": {
"Timeout": "00:00:30"
}
},
"ContentSite": {
"DatasetId": "<<dataset-id>>",
"ApiKey": "<<api-key>>",
"ServerUrl": "<<server-url>>",
"Timeout": "00:00:03",
"Tracker": {
"Timeout": "00:00:10"
},
"Recommender": {
"Timeout": "00:00:05"
},
"Searcher": {
"Timeout": "00:00:10"
}
}
}
}
When using named clients, you can use the IRelewiseClientFactory
to retrieve an instance of ITracker
, IRecommender
and ISearcher
:
IRelewiseClientFactory factory = provider.GetRequiredService<IRelewiseClientFactory>();
ITracker tracker = factory.GetClient<ITracker>("Integration");
Pull requests are always welcome.
Please fork this repository and make a PR when you are ready with your contribution.
Otherwise you are welcome to open an Issue in our issue tracker.
Relewise.Client.Extensions is licensed under the MIT license