MongoDbRepositoryCore 5.0.0
See the version list below for details.
dotnet add package MongoDbRepositoryCore --version 5.0.0
NuGet\Install-Package MongoDbRepositoryCore -Version 5.0.0
<PackageReference Include="MongoDbRepositoryCore" Version="5.0.0" />
<PackageVersion Include="MongoDbRepositoryCore" Version="5.0.0" />
<PackageReference Include="MongoDbRepositoryCore" />
paket add MongoDbRepositoryCore --version 5.0.0
#r "nuget: MongoDbRepositoryCore, 5.0.0"
#:package MongoDbRepositoryCore@5.0.0
#addin nuget:?package=MongoDbRepositoryCore&version=5.0.0
#tool nuget:?package=MongoDbRepositoryCore&version=5.0.0
📖 MongoDbRepository Developer's Guide (v4.5.0)
Welcome to the daily cookbook for the MongoDbRepository framework. This guide covers how to leverage the advanced v4.5 features, including Zero-Boilerplate Source Generators, AI Semantic Search, Microservices Caching, the Outbox Pattern, and Code-First Migrations.
1. Zero-Boilerplate DI (New in V4.5)
Forget manually registering dozens of repositories and services. V4.5 introduces a blazing-fast Roslyn Source Generator that wires up your entire database layer at compile-time.
Step 1: Add the [GenerateRepository] attribute to your entity.
[GenerateRepository]
[Cacheable] // Optional: Stacks the caching decorator automatically!
public class User : Entity
{
public string Name { get; set; }
}
Step 2: Call the auto-generated extension method in Program.cs. The generator automatically maps the interfaces, applies your decorators, and registers MediatR for background tasks.
C#
builder.Services.AddAutoGeneratedMongoRepositories();
builder.Services.AddAutoGeneratedMongoServices();
2. Generative AI & Vector Search
MongoDB Atlas supports native AI Vector Searches. This library reduces the complex aggregation pipelines into a single attribute and method call.
Step 1: Add the [VectorEmbedding] attribute to a float[] property on your entity. The repository will automatically provision the Atlas Search Indexes on startup.
C#
public class SupportArticle : Entity
{
public string Title { get; set; }
public string Content { get; set; }
[VectorEmbedding(Dimensions = 1536, Similarity = "cosine")]
public float[] ContentEmbedding { get; set; }
}
Step 2: Execute a Semantic Search natively.
C#
// Generate embedding via OpenAI, HuggingFace, etc.
float[] userQuestionVector = await _aiService.GetEmbeddingAsync("How do I reset my password?");
// Search, with optional pre-filtering!
var topArticles = await _articleRepo.SemanticSearchAsync(
queryVector: userQuestionVector,
limit: 5,
filter: article => article.IsActive // Pre-filters using standard LINQ
);
3. The Transactional Outbox Pattern (Guaranteed Events)
In a distributed system, saving a database record and firing an event (like sending a welcome email) is dangerous. If the server crashes between the two, the event is lost. V4.5 handles this flawlessly with a Zero-Config Outbox.
When you attach an event using IHasDomainEvents and save the entity, the repository serializes the MediatR event into a System_Outbox MongoDB collection inside the exact same ACID transaction.
Thanks to v4.5 Source Generators, the Background Worker and MediatR are now automatically registered for you! A background worker safely leases the message, fires the MediatR event, and retries on failure.
C#
user.AddDomainEvent(new UserRegisteredEvent(user.Id));
await _userRepo.AddAsync(user); // 100% Guaranteed Delivery
4. Distributed Cluster Caching (Redis)
If you run multiple instances of your API (e.g., in Kubernetes), standard RAM caching leads to stale data. V4.5 introduces the DistributedCachingRepositoryDecorator.
By registering your cache settings, the library uses Microsoft's IDistributedCache. If Pod A updates a user, it deletes the key from Redis, meaning Pods B, C, and D instantly fetch fresh data on their next request!
C#
builder.Services.AddMongoDbRepositories(db => { ... }, cache =>
{
cache.ApplicationName = "BillingApi";
});
5. Code-First Migrations
Need to seed an Admin user or rename a property across 1 million documents? Write a migration script. The framework will automatically run it on application startup and track its execution.
C#
public class Migration_001_SeedAdmin : IMongoMigration
{
public int Version => 1;
public async Task UpAsync(IMongoDatabase database)
{
var users = database.GetCollection<User>("users");
await users.InsertOneAsync(new User { Email = "admin@system.com", Role = "SuperAdmin" });
}
}
6. Mockless Unit Testing
Stop mocking IMongoCollection! We ship a blazing-fast, thread-safe fake that implements IRepository<T, TId> and executes your queries in memory.
C#
[Fact]
public async Task GetActiveUsers_ReturnsCorrectData()
{
// Arrange: Use the fake repository (0 milliseconds execution!)
var fakeRepo = new InMemoryRepository<User, Guid>();
fakeRepo.Seed(new[] { new User { Id = Guid.NewGuid(), IsActive = true, Name = "Alice" } });
var service = new UserService(fakeRepo);
// Act
var activeUsers = await service.GetActiveUsersAsync();
// Assert
Assert.Single(activeUsers);
}
| 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 is compatible. 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. |
-
net10.0
- FluentValidation (>= 12.1.1)
- MediatR (>= 14.1.0)
- Microsoft.AspNetCore.DataProtection (>= 10.0.5)
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Caching.Memory (>= 10.0.5)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- MongoDB.Driver (>= 3.7.1)
- Polly (>= 8.6.6)
-
net9.0
- FluentValidation (>= 12.1.1)
- MediatR (>= 13.1.0)
- Microsoft.AspNetCore.DataProtection (>= 9.0.15)
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 9.0.15)
- Microsoft.Extensions.Caching.Memory (>= 9.0.15)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.15)
- MongoDB.Driver (>= 3.7.1)
- Polly (>= 8.6.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.4 | 102 | 5/14/2026 |
| 5.0.3 | 94 | 4/30/2026 |
| 5.0.2 | 96 | 4/25/2026 |
| 5.0.1 | 89 | 4/23/2026 |
| 5.0.0 | 110 | 4/21/2026 |
| 4.5.10 | 108 | 4/13/2026 |
| 4.5.4 | 102 | 4/10/2026 |
| 4.5.3 | 95 | 4/9/2026 |
| 4.5.2 | 96 | 4/9/2026 |
| 4.5.1 | 99 | 4/9/2026 |
| 4.1.0 | 101 | 4/9/2026 |
| 4.0.0 | 110 | 3/25/2026 |
| 3.4.5 | 112 | 3/20/2026 |
| 3.4.0 | 100 | 3/20/2026 |
| 3.3.0 | 109 | 3/20/2026 |
| 3.2.2 | 111 | 3/15/2026 |
| 3.2.1 | 107 | 3/15/2026 |
| 3.2.0 | 112 | 3/14/2026 |
| 3.1.0 | 109 | 3/6/2026 |
| 3.0.2 | 111 | 3/1/2026 |