RepositoryKit.MongoDB
9.0.3
dotnet add package RepositoryKit.MongoDB --version 9.0.3
NuGet\Install-Package RepositoryKit.MongoDB -Version 9.0.3
<PackageReference Include="RepositoryKit.MongoDB" Version="9.0.3" />
<PackageVersion Include="RepositoryKit.MongoDB" Version="9.0.3" />
<PackageReference Include="RepositoryKit.MongoDB" />
paket add RepositoryKit.MongoDB --version 9.0.3
#r "nuget: RepositoryKit.MongoDB, 9.0.3"
#:package RepositoryKit.MongoDB@9.0.3
#addin nuget:?package=RepositoryKit.MongoDB&version=9.0.3
#tool nuget:?package=RepositoryKit.MongoDB&version=9.0.3
<div align="center"> <img src="logo-64x64.png" width="120" alt="RepositoryKit logo" />
RepositoryKit.MongoDb
MongoDB Implementation for RepositoryKit
</div>
📦 Package
This package provides the MongoDB implementation of RepositoryKit’s abstractions.
It enables consistent, testable, and flexible repository patterns for MongoDB projects —
without unnecessary UnitOfWork or transaction layers.
✅ Implementations
Class | Purpose |
---|---|
MongoReadOnlyRepository<TEntity, TContext> |
Read-only LINQ-style queries for MongoDB |
MongoRepository<TEntity, TContext> |
Full-featured CRUD repository for MongoDB |
🚀 Usage Examples
1. Register in DI (Startup or Program.cs)
builder.Services.AddSingleton<IMongoClient>(_ => new MongoClient("mongodb://localhost:27017"));
builder.Services.AddScoped<IMongoDatabase>(sp =>
sp.GetRequiredService<IMongoClient>().GetDatabase("SampleDb"));
builder.Services.AddScoped<IProductRepository, ProductRepository>();
2. Basic Repository Usage (Minimal API)
app.MapPost("/products", async (IProductRepository repo, Product product) =>
{
await repo.AddAsync(product);
return Results.Created($"/products/{product.Id}", product);
});
3. Custom Repository Inheritance & Usage
Custom Repository Interface and Implementation
public interface IProductRepository : IRepository<Product>
{
Task<List<Product>> GetExpensiveProductsAsync(decimal minPrice);
}
public class ProductRepository : MongoRepository<Product, IMongoDatabase>, IProductRepository
{
public ProductRepository(IMongoDatabase db) : base(db) { }
public async Task<List<Product>> GetExpensiveProductsAsync(decimal minPrice)
{
return await _collection.Find(p => p.Price > minPrice).ToListAsync();
}
}
Endpoint Usage
app.MapGet("/products/expensive", async (IProductRepository repo, decimal minPrice) =>
{
var expensive = await repo.GetExpensiveProductsAsync(minPrice);
return Results.Ok(expensive);
});
4. All RepositoryKit.Extensions Can Be Used
All LINQ-based RepositoryKit.Extensions (like Shuffle
, FirstOrNone
, GroupBySelect
, SafeDistinct
, etc.)
can be used directly in your MongoDB sample:
var products = await repo.GetAllAsync();
var shuffled = products.Shuffle().ToList();
🚨 Exception Handling
Repository operations wrap errors with the standard RepositoryException
from RepositoryKit.Core
:
try
{
await repo.AddAsync(product);
}
catch (RepositoryException ex)
{
// Handle or log error info
}
🤝 Dependencies
- RepositoryKit.Core
- MongoDB.Driver (official MongoDB driver)
📜 License
MIT © Ataberk Kaya
📎 This package is the official MongoDB provider for RepositoryKit
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- MongoDB.Driver (>= 3.4.0)
- RepositoryKit.Core (>= 9.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RepositoryKit.MongoDB:
Package | Downloads |
---|---|
RepositoryKit
Umbrella package for RepositoryKit - a modular repository pattern infrastructure that supports EF Core, MongoDB and clean LINQ extensions. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial stable version for MongoDB repositories compatible with .NET 9.