Version v14 (and Earlier)
Learn How to Install, Initialize and Create Classes for Version 14 of the SDK
Introduction
The basic concepts of the SDK are documented at the root page, linked below. Please note, they are the same for all versions of this package.
.NETThis document focuses on the initialization of the SDK and how to use the concrete client classes.
Install the SDK
The SDK is available on nuget.org. You can install it with:
Manually Creating Classes
The main entry class is SquidexClientManager
, which handles authentication and creates the actual client classes, where each client is used for one endpoint such as assets, schemas and so on.
The client will create an access token using the App client credentials and cache this token in the memory for 30 days. When the token expires, it is recreated automatically. The cache is not shared between the instances of your application and not needed.
Read more about the authentication flow and best practices below:
AuthenticationTo instantiate the client manager, you need the App Name, the Client Id and Client Secret. For self-hosted installations, the URL is also needed. For Squidex Cloud it is https://cloud.squidex.io
.
Configure Multiple Apps
The SDK supports multiple Apps using the normal options. When you create a request using an end point client you have to define the App Name, and the client manager picks the correct credentials. When you create a content client, you can also specify the App Name.
Creating Classes with Dependency Injection
If you use Dependency Injection (especially in ASP.NET Core) you can use the following package:
This package provides extension methods to register the client manager at the service collection.
You can inject ISquidexClientManager
to your other classes.
This configuration uses the Options Pattern, so it can also be configured the following way:
Another option is to bind it to a configuration section as follows:
Configure Multiple Apps
You can also configure multiple Apps using the normal options as follows:
Configure the HTTP pipeline
The package also integrates the HttpClientFactory to implement resilient HTTP requests. For example, this can be used to enable logging or to integrate Polly, a resilience and transient-fault-handling library.
You can make changes to the HTTP pipeline using the following method:
Use Concrete Clients
The classes for concrete endpoints can be created with the client manager. These instances are not cached and a new instance is returned for each call. Therefore, you should keep the instance as a local variable and field, and use them as often as possible.
The content clients are also not cached. They can be created using the following method:
Using Dependency Injection
The endpoint clients are registered in the service locator. Therefore, you can also inject endpoint classes to your service class MyService
.
The content clients need parameters to be created. Therefore, you have to register them manually.
Last updated
Was this helpful?