Skip to content
This repository was archived by the owner on Feb 4, 2026. It is now read-only.

Repository files navigation

FluentCMS.Repositories

A flexible generic repository pattern implementation supporting multiple database types.

Overview

FluentCMS.Repositories provides a standardized way to implement data access with support for multiple database providers:

  • MongoDB
  • SQL Server
  • SQLite

The library offers a consistent API surface while enabling database-specific optimizations behind the scenes.

Features

  • Generic repository interfaces for any entity type with a GUID identifier
  • Consistent CRUD operations across all database implementations
  • Flexible querying with filtering, sorting, and pagination
  • Support for MongoDB, SQL Server, and SQLite
  • Dependency injection support for easy integration

Getting Started

Prerequisites

  • .NET 8.0 or later
  • Connection to your preferred database (MongoDB, SQL Server, or SQLite)

Installation

Install the NuGet packages for your preferred database provider:

# For MongoDB
dotnet add package FluentCMS.Repositories.MongoDb
# For SQL Server
dotnet add package FluentCMS.Repositories.SqlServer
# For SQLite
dotnet add package FluentCMS.Repositories.Sqlite

Basic Usage

  1. Create an entity class that implements IBaseEntity:
usingFluentCMS.Repositories.Abstractions.Entities;publicclassProduct:IBaseEntity{publicGuidId{get;set;}publicstringName{get;set;}=string.Empty;publicdecimalPrice{get;set;}publicstringDescription{get;set;}=string.Empty;}
  1. Configure the repositories in your service registration:
// MongoDB setupservices.AddMongoDbRepositories(options =>{options.ConnectionString="mongodb://localhost:27017";options.DatabaseName="YourDatabaseName";});// SQL Server setupservices.AddSqlServerRepositories(options =>{options.ConnectionString="Server=(localdb)\\mssqllocaldb;Database=YourDatabase;Trusted_Connection=True;";});// SQLite setupservices.AddSqliteRepositories(options =>{options.ConnectionString="Data Source=YourDatabase.db";});
  1. Inject and use the repository in your services:
publicclassProductService{privatereadonlyIBaseEntityRepository<Product>_productRepository;publicProductService(IBaseEntityRepository<Product>productRepository){_productRepository=productRepository;}publicasyncTask<Product?>GetProductById(Guidid){returnawait_productRepository.GetById(id);}publicasyncTask<IEnumerable<Product>>GetExpensiveProducts(decimalpriceThreshold){returnawait_productRepository.Query(p =>p.Price>priceThreshold);}publicasyncTaskAddProduct(Productproduct){await_productRepository.Add(product);}publicasyncTaskUpdateProduct(Productproduct){await_productRepository.Update(product);}publicasyncTaskDeleteProduct(Guidid){await_productRepository.Delete(id);}}

Advanced Querying

Filtering

// Simple filtervarproducts=await_repository.Query(p =>p.Price>100);// Complex filtervarproducts=await_repository.Query(
p =>p.Price>100&&p.Name.Contains("smartphone")&&p.IsAvailable);

Sorting

// Create sort optionsvarsortOptions=newSortOptions<Product>();sortOptions.Add(p =>p.Price,SortDirection.Descending);sortOptions.Add(p =>p.Name);// Ascending is default// Apply sortingvarproducts=await_repository.Query(filter:null,sortOptions:sortOptions);

Pagination

// Skip 20 items and take 10varproductsPage=await_repository.Query(filter:null,sortOptions:null,skip:20,take:10);// Get total count for paginationvartotalCount=await_repository.Count();

Combined Querying

// Filter, sort, and paginatevarqueryOptions=newQueryOptions<Product>{Filter= p =>p.Category=="Electronics",Sort=newSortOptions<Product>(),Skip=10,Take=5};queryOptions.Sort.Add(p =>p.Price,SortDirection.Descending);varproducts=await_repository.Query(queryOptions);

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages