Repository

The ubiquitous repository pattern as it is implemented by RCommon.

There has been much said about the repository pattern over the years. Perhaps the most influential advocate for the repository pattern is Martin Fowler.

Through the repository pattern, we are able to implement a variety of useful techniques such as eager loading, pagination, and unit of work (UoW).

public class DeleteLeaveRequestCommandHandler : IRequestHandler<DeleteLeaveRequestCommand>
{
    private readonly IFullFeaturedRepository<LeaveRequest> _leaveRequestRepository;

    public DeleteLeaveRequestCommandHandler(IFullFeaturedRepository<LeaveRequest> leaveRequestRepository)
    {
        this._leaveRequestRepository = leaveRequestRepository;
        this._leaveRequestRepository.DataStoreName = "LeaveManagement";
    }

    public async Task<Unit> Handle(DeleteLeaveRequestCommand request, CancellationToken cancellationToken)
    {
        var leaveRequest = await _leaveRequestRepository.FindAsync(request.Id);

        if (leaveRequest == null)
            throw new NotFoundException(nameof(LeaveRequest), request.Id);

        await _leaveRequestRepository.DeleteAsync(leaveRequest);
        return Unit.Value;
    }
}

Persistence Features

RCommon provides a variety of strategies for persistence. Our opinion is that object relational mappers (ORM's) can be divided into three categories with distinct but not exclusive feature sets. Categorically, these features have pros and cons but in general, you find that the more features an ORM has, the easier it is to do certain things programmatically which ultimately saves you time. However, those extra features often cost you performance.

Ultimately you are choosing an ORM based on your architectural AND operational needs. RCommon has implemented three of the most widely adopted ORMs available today - one from each category which ultimately gives you the flexibility you need to adapt as your needs change which frees you from much of the heartbreak of "Day-Zero" decisions.

FeatureGraph MapperLinq MapperSQL Mapper

Implements IQueryable

Eager Loading

Lazy Loading

Graph Persistence (nested entities)

Change Tracking

ACID Transactions

Custom SQL/Queries

Fluent Entity Mapping

Persistence Events

Unit of Work Support

Supported Object Relational Mappers (ORMs)

ORMGraph MapperLinq MapperSQL Mapper

Entity Framework Core

Mongo DB Client (soon)

Linq2Db

Dapper

Last updated