Use the .NET library
The .NET client library calls the Amplia Reg API for you. The .NET examples in this guide use the IAmpliaRegService
interface it provides. In other languages, call the REST API directly: see API authentication and errors.
Before you start
- The endpoint and the API key. See Get started.
- A project on .NET Framework 4.6.1 or later, or .NET Core 2.0 or later. The library targets .NET Standard 2.0.
Install the package
Add the NuGet package Lacuna.AmpliaRegNg.Client:
dotnet add package Lacuna.AmpliaRegNg.Client
Configure in ASP.NET Core
-
Add the code below to the
ConfigureServices()method of the Startup.cs class:public void ConfigureServices(IServiceCollection services) {...services.AddAmpliaReg().Configure(Configuration.GetSection("AmpliaReg"));} -
In appsettings.json, add the
AmpliaRegsection:{..."AmpliaReg": {"Endpoint": "YOUR_INSTANCE_ENDPOINT_HERE","ApiKey": "YOUR_API_KEY_HERE"},...} -
Where your application calls the API, request an
IAmpliaRegServiceinstance through dependency injection:using Lacuna.AmpliaRegNg.Client;public class MyController : ApiController {private readonly IAmpliaRegService ampliaRegService;public MyController(IAmpliaRegService ampliaRegService) {this.ampliaRegService = ampliaRegService;}...}
Configure in other .NET applications
Use the endpoint and the API key to get an IAmpliaRegService implementation from the static AmpliaRegServiceFactory class:
using Lacuna.AmpliaRegNg.Client;
public class MyController : ApiController {
private readonly IAmpliaRegService ampliaRegService;
public MyController() {
this.ampliaRegService = AmpliaRegServiceFactory.GetService(new AmpliaRegOptions() {
Endpoint = ConfigurationManager.AppSettings["AmpliaRegEndpoint"],
ApiKey = ConfigurationManager.AppSettings["AmpliaRegApiKey"],
});
}
...
}
In the example, the endpoint and the key are in the appSettings section of web.config. You can keep them in a different
location. In production, keep the API key in a secrets vault or in an environment variable.
Set the culture
The library tells the API the culture of the current thread (Thread.CurrentThread.CurrentUICulture). To use a fixed culture, set
CultureName.
In ASP.NET Core, in the AmpliaReg section of appsettings.json:
{
...
"AmpliaReg": {
...,
"CultureName": "en-US"
},
...
}
In other .NET applications, in the AmpliaRegOptions object:
this.ampliaRegService = AmpliaRegServiceFactory.GetService(new AmpliaRegOptions() {
...,
CultureName = "en-US",
});
Handle exceptions
The IAmpliaRegService methods can throw:
AmpliaRegException: an API error, usually a request that can be fixed. TheCodeproperty has the error code.RestErrorException: an HTTP call error. TheStatusCodeproperty has the HTTP status code.
Features the library does not have
The library has no method for these routes:
- The
v2order creation route. - The holder type list,
GET /api/holder-types.
For these routes, call the REST API directly, with the same endpoint and API key.