---
title: Client class in the .NET Client API
slug: cms-12/docs/client-class
docTags: 
createdAt: 2026-08-10T15:55:56.000Z
---

The `Client` class in the .NET Client API for Optimizely Search & Navigation covers common operations such as indexing objects, getting documents, deleting documents, and searching.

The `Client` class, abstracted by the `IClient` interface acts as a gateway or façade for the Optimizely Search & Navigation service. The class covers most operations you would want to perform, such as indexing objects, getting documents, deleting documents, and searching. The `Client` class methods do not, however, map directly to the service. These methods enforce several conventions, most of which can be customized, to provide additional functionality and a more convenient way of working with the service. `Client` is further enhanced by several extension methods, most notably the `Search` method, the starting point for building search requests using a fluent API.

## Obtain an IClient instance

You can instantiate the `Client` class directly, but its constructor requires several parameters. As these parameters primarily concern configuration details, the `Client` class also has a parameter-less static method, `CreateFromConfig`, which returns an instance of the class based on configuration settings. To use the `Client.CreateFromConfig` method, you must first add a configuration section to your solution. See [.NET Client API](docId:7DPNSuEGiCUQ8fvjuRqZl).

With that in place, you can obtain an instance of the `Client` class:

`IClient client = Client.CreateFromConfig();`

## Manage instances

Creating an instance of the `Client` class is not a costly operation, but performance may be affected. In many scenarios, you also want to modify the instance before usage, meaning you want to instantiate it on application startup. You should only use a single instance per application or a few long-lived instances with different settings or conventions.

You can accomplish this in several ways, depending on the type of application in which the `Client` class is being used. In an ASP.NET MVC website, you can configure the `DependencyResolver` to automatically inject the instance into controllers. Likewise, an `Inversion` of `Control` container can inject the instance into the presenter in a Web Forms site using the MVP pattern. In other situations, you can manage the instance in a custom class in a Singleton-like fashion. The following example illustrates how to wire up injection of the `Client` class into controllers in an ASP.NET site that uses the Autofac MVC integration.

```csharp
protected void Application_Start() {
  var builder = new ContainerBuilder();
  builder.Register(x => CreateSearchClient()).As<IClient>().SingleInstance();
  var container = builder.Build();
  DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}

private static Client CreateSearchClient() {
  var client = Client.CreateFromConfig();
  //Any modifications required goes here    
  return client;
}
```

### Use Client instance with CMS

:::hint{type="warning"}
**Important**
Do not create a new instance of `IClient` if you are using Optimizely Search & Navigation with Optimizely Content Management System (CMS), since content indexing and index querying may fail. When using Optimizely Search & Navigation with CMS, you should never create an instance of `IClient`.
:::

If you have `EPiServer.Find.Cms` installed, there is a configured instance already in `SearchClient.Instance`. Because `Client` holds the convention information, if an instance is created *after* you apply the conventions, it may cause the content indexing and querying to fail because it overwrites previous configurations.

Instead, use `SearchClient.Instance` to get an instance of `IClient`, configured through an initialization module in `EPiServer.Find.Cms`.

## Use inheritance

Inheritance is supported when you search using the [Client](docId\:UNQusUQ7qiw14HnbONJB2) class. For example, if you have two classes, `User` and `Author` and you search for users, you also get matching authors back.

```csharp
searchResult = client.Search<User>()
    .For("John")
    .InField(x => x.Name)
    .GetResult();

var isUser = (searchResult.First is User);
//isUser IS true

var isAuthor = (searchResult.First is Author);
//isAuthor MIGHT be true
```

You also can search over types that implement a specific interface.
