Deveel Repository
Deveel
  • Why Another Repository Pattern Library?
  • The Repository Pattern
  • Getting Started
  • Customize the Repository
  • Multi-Tenancy of Data Sources
  • User Entities
  • Repository Implementations
    • In-Memory Repositories
    • Entity Framework Core Repositories
    • MongoDB Repositories
  • The Entity Manager
    • Caching Entities
Powered by GitBook
On this page
  • Installation
  • Requirements
  • The Kernel Package
  • The Drivers
  • Instrumentation
  • Consuming the Repository
Edit on GitHub

Getting Started

PreviousThe Repository PatternNextCustomize the Repository

Last updated 1 year ago

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:

Topic
Description

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 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:

Version
.NET Runtime

=< 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.

Driver
Package
Description

Deveel.Repository.InMemory

A very simple implementation of the repository pattern that stores the data in-memory.

Deveel.Repository.MongoFramework

Deveel.Repository.EntityFramework

Instrumentation

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:

Service
Description

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.

Repository Pattern
.NET 6.0
Dependency Injection
Using the Entity Framework Core Repository
Entity Framework Core
Using the MongoDB Repository
MongoDB
Using the In-Memory Repository
The Entity Manager
Extending the Repository
Multi-Tenancy
In-Memory
MongoDB
MongoFramework
Entity Framework Core
Entity Framework Core