Squidex
  • Welcome to Squidex
  • Getting Started
    • Squidex Cloud
    • Installation Instructions
      • Platforms
        • Install on Kubernetes
        • Install on AWS (Deprecated)
        • Install on AWS EC2 using Docker
        • Install on Azure
        • Install on Azure using ARM
        • Install on Google Cloud Platform (GCP)
        • Install on Docker
        • Install on Heroku
        • Install on IIS
        • Install on Render
        • Install on Vultr
      • Configuration
        • Deploying the Image Resizer Service
      • Troubleshooting and Support
        • Diagnose Runtime Issues
        • Restoring Deleted Apps
      • Install Identity (Deprecated)
      • External Identity Providers
        • Azure AD (OAuth) with Squidex
    • Contributing and Developing
      • Building
      • Developing
      • Extensions
        • Custom Rule Action
      • Contributing
      • Architecture
      • Translating
      • Squidex Docs Program
    • Roadmap
    • Quick Start Guides
      • Vue.js Blog with Squidex
      • React.js Blog with Squidex
      • Angular Blog with Squidex
  • Documentation
    • Introduction and Use Case
    • Concepts
      • Apps
      • Teams
      • Schemas
        • Field Rules
      • Content
        • Scheduled Publishing
      • Assets
        • Querying Assets
      • Localization
      • Migrations
      • Roles & Permissions
      • Rules
        • Publish an Event to Azure Queues using Rules
        • Populate Elasticsearch Index
      • Backups
      • Subscriptions
        • App Subscriptions v/s Team Subscriptions
      • Notifications
      • Dashboard
      • Workflows
    • Software Development Kits
      • TypeScript
      • .NET
        • Version v14 (and Earlier)
        • Version v15 (and Later)
      • PHP
      • Java
    • Developer Guides
      • API
        • Authentication
        • Postman
        • Queries
        • Assets
      • Automation Tools (CLI)
      • Scripting
        • Scripting Helper Methods
      • Embed Content
      • Custom Workflows
      • Custom Editors
      • Custom Sidebars
      • Preview Content
      • Rule Formatting
        • Simple
        • Script
        • Liquid
      • Tutorials
        • Building a Blog with Squidex and Next.js
  • Next
    • Squidex 3.0: API Compatibility
Powered by GitBook
On this page
  • Introduction
  • Install the SDK
  • Creating Classes Manually
  • Configuring Multiple Apps
  • Creation of Classes with Dependency Injection
  • Configure Multiple Apps
  • Configure the HTTP Pipeline
  • Use Concrete Clients
  • Using with Dependency Injection

Was this helpful?

  1. Documentation
  2. Software Development Kits
  3. .NET

Version v15 (and Later)

Learn How to Install, Initialize and Create Classes for Version 15 of the SDK

PreviousVersion v14 (and Earlier)NextPHP

Last updated 2 years ago

Was this helpful?

Introduction

The basic concepts of the SDK are documented on the root page, linked below (this is because they are the same for all versions of this package):

This document focuses on the initialization of the SDK and how to use the concrete client classes.

Install the SDK

The SDK is available on . You can install it with:

dotnet add package Squidex.ClientLibrary

Creating Classes Manually

The main entry class is ISquidexClient 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 creates an access token using the client credentials and caches 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 it is not needed.

Read more about the authentication flow and best practices below:

To instantiate the client you need the App Name, the Client Id and Client Secret. For self-hosted installations the URL is also required. For Squidex Cloud it is https://cloud.squidex.io.

ISquidexClient client =
    new SquidexClient(
        new SquidexOptions
        {
            AppName = "...",
            ClientId = "...",
            ClientSecret = "...",
            Url = "https://cloud.squidex.io"
        });

Configuring Multiple Apps

The client no longer supports multiple Apps anymore. Use one client per App.

Creation of Classes with Dependency Injection

dotnet add package Squidex.ClientLibrary.ServiceExtensions

This package provides extension methods to register the Squidex Client at the service collection.

services
    .AddSquidexClient(options =>
    {
        options.AppName = "app";
        options.ClientId = "id";
        options.ClientSecret = "secret";
        options.Url = "https://custom.squidex.io";
    });

You can inject ISquidexClient to your other classes.

services.AddSquidexClient()
    .Configure<SquidexServiceOptions>(options =>
    {
        options.AppName = "app";
        options.ClientId = "id";
        options.ClientSecret = "secret";
        options.Url = "https://custom.squidex.io";
    });

Another option is to bind it to a configuration section as follows:

services.AddSquidexClient();
services.Configure<SquidexServiceOptions>(
    configuration.GetSection("squidex"));

Configure Multiple Apps

Multiple Apps can be managed with the service provider by using named registrations as shown in the snippet below:

services
    .AddSquidexClient(options =>
    {
        options.AppName = "app1";
        options.ClientId = "id1";
        options.ClientSecret = "secret1";
    })
    .AddSquidexClient("app2", options =>
    {
        options.AppName = "app2";
        options.ClientId = "id2";
        options.ClientSecret = "secret2";
    })
    .AddSquidexClient("app3", options =>
    {
        options.AppName = "app3";
        options.ClientId = "id3";
        options.ClientSecret = "secret3";
    });

Inject the ISquidexClientProvider instance to resolve a concrete client.

class MyService
{
    public MyService(ISquidexClientProvider provider)
    {
        // Get the default client, that has been registered without a name.
        var client1 = provider.Get();
        
        // Get a named client.
        var client2 = provider.Get("app2");
        var client3 = provider.Get("app3");
    }
}

Configure the HTTP Pipeline

You can implement changes to the HTTP pipeline using the following method:

serviceCollection.AddSquidexHttpClient()
   .AddHttpMessageHandler(() =>
   {
       // YOUR CODE
   });

Use Concrete Clients

The classes for concrete endpoints are properties of the client class. These instances are cached and a single instance is shared between all calls. Therefore, storing the instance in a separate variable is not required.

var assetsClient = client.Assets;

var assets1 = await assetsClient.GetAssetsAsync();

// Just use the client directly.
var assets2 = await client.Assets.GetAssetsAsync();

The content clients are also cached and can be resolved with the following method:

var blog1 = client.Contents<BlogPost, BlogPostData>("blog1");
var blog1 = client.Contents<BlogPost, BlogPostData>("blog1");

ReferenceEquals(blog1, blog2) == true;

The content clients are cached internally using a thread safe dictionary.

Using with Dependency Injection

The endpoint clients are not registered in the service locator. You have to register them manually if needed. It is best to use the root client class, especially if you work with multiple Apps. For performance reasons, this is not required.

services.AddSquidexClient(x => x.Assets);

If you use (especially in ASP.NET Core) you can use the following package:

The configuration uses the , so it can also be configured in the following way:

The package also integrates the to implement resilient HTTP requests. For example, this can be used to enable logging or to integrate , a resilience and transient-fault-handling library.

.NET
nuget.org
Authentication
Dependency Injection
Options Pattern
HttpClientFactory
Polly