---
title: "Datasource factory"
slug: "datasource-factory"
abstract: "Overview of the Datasource factory and how to create datasource instances."
---
# Datasource factory

The datasource factory creates datasource instances for the two types of datasources.

> [!note]
> The `client` variable in the following code examples refers to the `IMClient` instance. When using the Web SDK, the variable name can be chosen freely, but it is also called `client` at instantiation in the documentation.

## Create flat datasources

To create a flat datasource, pass a unique name for the datasource to the `CreateFlatDataSource` method:

```shell
IFlatDataSource flatDataSource = MClient.DataSourceFactory.CreateFlatDataSource("NewFlatDataSource");

```

## Create hierarchical datasources

To create a hierarchical datasource, pass a unique name for the datasource to the `CreateHierarchicalDataSource` method:

```shell
IHierarchicalDataSource hierachicalDataSource = MClient.DataSourceFactory.CreateHierarchicalDataSource("NewHierarchicalDataSource");

```

> [!note]
> The datasource instance is not persisted. The factory only creates an object. If the datasource needs to be persisted, use the `CreateAsync` on the `IDataSourcesClient`.