Getting Started
The Deveel Repository is a framework that provides a set of abstractions and implementations of the Repository Pattern, 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:
Learn how to use the Repository pattern with Entity Framework Core
Accessing MongoDB databases through the Repository pattern
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
Installation
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.
Requirements
Until the version 1.2.5, the library is built on top of the .NET 6.0 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
The Kernel Package
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:
Install-Package Deveel.Repository.Core
or using the .NET CLI:
dotnet add package Deveel.Repository.Core
The Drivers
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
An implementation of the repository pattern that stores the data in a MongoDB database (using the MongoFramework library).
Deveel.Repository.EntityFramework
An implementation of the repository pattern that stores the data in a relational database, using the Entity Framework Core.
Instrumentation
The library provides a set of common extensions to leverage the Dependency Injection pattern, and to simplify the registration of the services in the dependency injection container.
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:
public void ConfigureServices(IServiceCollection services) {
services.AddRepository<InMemoryRepository<MyEntity>>();
}
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:
public void ConfigureServices(IServiceCollection services) {
services.AddRepository<MyCustomRepository>();
}
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.
Consuming the Repository
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).
Last updated