Extend the .NET SDK

When developing solutions with Sitefinity Insight, you can inherit and extend any of the .NET SDK clients. To create new clients, use the following abstract classes:

  • CrudClientBase<T>
  • CrudAndGetAllClientBase <TAll, T, TId>
  • DatacenterBoundClientBase
  • ClientBase

This article demonstrates how to create a client from scratch. The client gets all contacts in Sitefinity Insight and can also get a single contact and their interactions, reported to Sitefinity Insight.

NOTE: In this article, all visitors - both anonymous visitors or contacts who provided their email address, are referred as contacts.

You will need the following classes to create the sample:

  • Sitefinity Insight contact:

  • Sitefinity Insight contact interaction:

Implement the client

To implement the client, you inherit from the DatacenterBoundClientBase abstract class. You use the methods and constructors of the class to make requests to the Sitefinity Insight API Server. The following code sample demonstrates how to implement the client:

The following sample demonstrates how to get twenty contacts from Sitefinity Insight and then get the details and twenty interactions of the first contact:

Abstract classes

The following table lists the abstract classes that you can use to extend the .NET SDK, together with their constructors, properties, and methods.

ClientBase

An abstract base class, containing logic for making PUT, POST, DELETE, and GET requests to the Sitefinity Insight API Server.

Constructors

  • protected ClientBase()
  • protected ClientBase(IAccessToken accessToken)
  • protected ClientBase(IAccessToken accessToken, string serverAddress)

Properties

  • public int? Timeout

DataCenterBoundClientBase

This abstract class inherits from ClientBase class and provides a basis infrastructure to simplify the implementation of new clients for data center bound operations. You use this class when you want to call a specific API endpoint that requires the data center key as part of the request header. 
To create advanced abstraction over CRUD (Create, Read, Update, and Modify) operations, or to automatically set restrictions for entities, you use different classes, such as CrudAndGetAllClientBase, described below.

Constructors

  • protected DatacenterBoundClientBase(IAccessToken accessToken, string datacenterKey)
  • protected DatacenterBoundClientBase(string datacenterKey)
  • protected DatacenterBoundClientBase(string serverAddress, string datacenterKey)

Properties

public string DatacenterKey { get; private set; }

CrudAndGetAllClientBase <TAll, T, TId>

An abstract class containing methods for creating, retrieving, updating, and deleting all artifacts. Inherits from DataCenterBoundClientBase.

Constructors

  • protected CrudAndGetAllClientBase(IAccessToken token, string datacenterKey)
  • protected CrudAndGetAllClientBase(IAccessToken token, string serverAddress, string datacenterKey)

Properties

protected abstract string EntityUrl { get; }

Methods

  • public Task<CollectionResponse<TAll>> GetAll(LoadOptions loadOptions)
  • public Task<T> Create(T entity)
  • public Task<T> GetById(TId id)
  • public Task<T> Update(T entity)
  • public Task Delete(TId id)

Was this article helpful?

Next article

.NET SDK data types