Getting Started
Last updated
Last updated
The Deveel Repository is a framework that provides a set of abstractions and implementations of the , to simplify the access to data sources in your application.
Below you will find a quick and generic guide to start using the framework in your application.
To learn about the specific usage of the framework, you can read the following documentation:
Interface a volatile and in-process storage using a Repository pattern.
Provide your application with a business layer on top of the Repository for additional functions (logging, validation, normalization, caching, event sourcing, etc.)
Learn how to create a custom repository to access your data source, according to your specific data logic
Learn how to use the framework in a multi-tenant application
The framework is based on a kernel package, that provides the basic interfaces and abstractions, and a set of drivers that implement the interfaces to access different data sources.
When installing any of the libraries of the framework, the kernel package (Deveel.Repository.Core
) will be installed as a dependency, so you don't need to install it explicitly.
Until the version 1.2.5, the library is built on top of the and requires a runtime that supports it: ensure that your application is configured to use the latest version of the runtime.
Since that version we have started targetting multiple runtimes of the .NET Framework, and the following table shows the compatibility matrix:
=< 1.2.2
.NET 6.0
>= 1.2.5
.NET 6.0, .NET 7.0
All the specific drivers are built on top of the kernel package, that provides the basic interfaces and abstractions to implement the repository pattern.
If you are interested developing a driver for a specific data source, you can use the kernel package as a dependency, and implement the interfaces to access the data source: you will still receive many benefits by using the abstractions provided by the library, simplifying your development and usage.
To install the package, run the following command in the Package Manager Console in your project folder:
or using the .NET CLI:
The library provides a set of drivers to access different data sources, that can be used as a dependency in your project.
Deveel.Repository.InMemory
A very simple implementation of the repository pattern that stores the data in-memory.
Deveel.Repository.MongoFramework
Deveel.Repository.EntityFramework
To register a repository in the dependency injection container, and be ready to use it in your application, you can use the AddRepository<TRepository>
extension method of the IServiceCollection
interface.
For example, if you want to register the default in-memory repository, you can use the following code:
If you have implemented your own repository, deriving from the IRepository<TEntity>
interface, or from one of the drivers-specific repositories (eg. MongoRepository<TEntity>
, EntityRepository<TEntity>
), or even if you have implemented your own driver, you can register it in the same way:
The type of the argument of the method is not the type of the entity, but the type of the repository: the library will use reflection to scan the type itself and find all the generic arguments of the IRepository<TEntity>
interface, and register the repository in the dependency injection container.
In fact, after that example call above, you will have the following services available to be injected into your application:
MyCustomRepository
The repository to access the data.
IRepository<MyEntity>
The repository to access the data.
IMyCustomRepository
The abstration that provides custom business logic and implementing the IRepository<MyEntity>
.
IQueryableRepository<MyEntity>
The repository to access the data using the LINQ syntax (if the repository implements it).
IPageableRepository<MyEntity>
The repository to access the data using pagination (if the repository implements it).
IFilterableRepository<MyEntity>
The repository to access the data using filters (if the repository implements it).
Learn how to use the Repository pattern with
Accessing databases through the Repository pattern
An implementation of the repository pattern that stores the data in a MongoDB database (using the library).
An implementation of the repository pattern that stores the data in a relational database, using the .
The library provides a set of common extensions to leverage the pattern, and to simplify the registration of the services in the dependency injection container.