Repositories
Configuring repositories in Konstrukt, the back office UI builder for Umbraco.
Repositories are used by Konstrukt to access the entity data stores. By default, collections will use a generic built in NPoco repository however you can define your own repository implementation should you wish to store your entities via an alternative strategy.
Defining a repository
To define a repository you create a class that inherits from the base class KonstruktRepository<TEntity, TId>
and implements all of its abstract methods.
Note: For all Impl
methods there are public alternatives without the Impl
suffix, however we have separate implementation methods in order to ensure all repositories fire the relevant Konstrukt events whether triggered via the Konstrukt UI or not.
Changing the repository implementation of a collection
SetRepositoryType<TRepositoryType>() : KonstruktCollectionConfigBuilder<TEntityType>
Sets the repository type to the given type for the current collection.
SetRepositoryType(Type repositoryType) : KonstruktCollectionConfigBuilder<TEntityType>
Sets the repository type to the given type for the current collection.
Accessing a repository in code
To help with accessing a repository (default or custom) Konstrukt has a IKonstruktRepositoryFactory
you can inject into your code base with a couple of factory methods to create the repository instances for you. Repositories should only be created via the repository factory as there are a number of injected depenedencies that can only be resolved by Konstrukt.
IKonstruktRepositoryFactory.GetRepository<TEntity, TId>() : KonstruktRepository<TEntity, TId>
Creates a repository for the given entity type. Konstrukt will search the configuration for the first section / collection with a configuration for the given entity type and use that as repository configuration.
IKonstruktRepositoryFactory.GetRepository<TEntity, TId>(string collectionAlias) : KonstruktRepository<TEntity, TId>
Creates a repository for the given entity type from the collection with the given alias.
Last updated