Repositories
Configure repositories in Umbraco UI Builder.
Repositories in Umbraco UI Builder manage entity data storage. By default, collections use a built-in NPoco repository. To use a different storage strategy, define a custom repository implementation.
Defining a Repository
Create a class that inherits from Repository<TEntity, TId>
and implements all abstract methods.
Changing the Repository Implementation of a Collection
Using the SetRepositoryType()
Method
SetRepositoryType()
MethodAssign a custom repository type to a collection.
Method Syntax
Example
Using the SetRepositoryType(Type repositoryType)
Method
SetRepositoryType(Type repositoryType)
MethodSets the repository type dynamically to the given type for the current collection.
Method Syntax
Example
Accessing a Repository in Code
To help with accessing a repository (default or custom) Umbraco UI Builder has an IRepositoryFactory
you can inject into your code base. This includes a couple of factory methods to create the repository instances for you.
Repositories should only be created via the repository factory as there are some injected dependencies that can only be resolved by Umbraco UI Builder.
Using the GetRepository<TEntity, TId>()
Method
GetRepository<TEntity, TId>()
MethodCreates a repository for the given entity type. Umbraco UI Builder will search the configuration for the first section/collection with a configuration for the given entity type. Then it will use that as a repository configuration.
Method Syntax
Example
Using the GetRepository<TEntity, TId>(string collectionAlias)
Method
GetRepository<TEntity, TId>(string collectionAlias)
MethodCreates a repository for the given entity type from the collection with the given alias.
Method Syntax
Example
Last updated
Was this helpful?