Factories
Sitecore Content Hub uses factories to simplify the process of creating instances of entities or data sources.
Entity factory
The entity factory creates entity instances based on a specific definition. Since entities are complex and their members can change at runtime, a factory is needed to ensure the instance is created with the correct members and configuration. Each new instance includes all necessary members.
Use the CreateAsync method to create a new entity. If you need to specify cultures for a new entity, make sure you include all of them during the creation process, because you cannot add or remove cultures later without reloading the entity.
For example, you can use the following method to create a new Asset entity instance with the default culture:
This example creates the entity instance by passing the definition name. Alternatively, you can pass the entity definition instance instead.
The entity instance is not persisted. The factory only creates an object. If the entity needs to be persisted, use the SaveAsync method on the IEntitiesClient.
Data source factory
The data source factory creates instances of the two types of data sources—flat data sources, which are simple lists of items, and hierarchical data sources, which are structured, nested data with parent-child relationships.
The data source instance is not persisted. The factory only creates an object. If the data source needs to be persisted, use the CreateAsync on the IDataSourcesClient.
Create flat data sources
To create a flat data source, pass a unique name to the CreateFlatDataSource method:
Create hierarchical data sources
To create a hierarchical data source, pass a unique name to the CreateHierarchicalDataSource method: