A cohesive set of infrastructure libraries for dotnet that utilizes abstractions for event handling, persistence, unit of work, mediator, distributed messaging, event bus, CQRS, email, and more
$ dotnet add package RCommon.EFCoreEntity Framework Core implementation of the RCommon persistence abstractions. Provides a fully-featured repository with LINQ queries, eager loading, change tracking, and automatic domain event integration -- all backed by EF Core's DbContext.
EFCoreRepository<TEntity> implementing IGraphRepository<T>, ILinqRepository<T>, IReadOnlyRepository<T>, and IWriteOnlyRepository<T>IQueryable<T> support for composable LINQ queries at the domain layerInclude / ThenInclude mapped to EF Core's IIncludableQueryableTracking property)ExecuteDeleteAsync for expression-based batch operationsIDataStoreFactoryRCommonDbContext base class implementing IDataStore for seamless factory resolutionISoftDelete are automatically filtered on reads and logically deleted on writesIMultiTenant are automatically filtered by tenant on reads and stamped with TenantId on writesdotnet add package RCommon.EFCore
// Configure in Program.cs or Startup
builder.Services.AddRCommon()
.WithPersistence<EFCorePerisistenceBuilder>(ef =>
{
ef.AddDbContext<ApplicationDbContext>("ApplicationDb", options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("ApplicationDb")));
ef.SetDefaultDataStore(defaults =>
defaults.DefaultDataStoreName = "ApplicationDb");
});
Your DbContext must inherit from RCommonDbContext:
public class ApplicationDbContext : RCommonDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) { }
public DbSet<Order> Orders => Set<Order>();
public DbSet<Customer> Customers => Set<Customer>();
}
Then inject and use the repository abstractions:
public class OrderService
{
private readonly IGraphRepository<Order> _orderRepo;
public OrderService(IGraphRepository<Order> orderRepo)
{
_orderRepo = orderRepo;
}
public async Task<ICollection<Order>> GetCustomerOrdersAsync(int customerId)
{
_orderRepo.Include(o => o.LineItems);
return await _orderRepo.FindAsync(o => o.CustomerId == customerId);
}
}
EFCoreRepository<TEntity> automatically supports soft delete and multitenancy when your entities implement the opt-in interfaces:
using RCommon.Entities;
public class Customer : BusinessEntity<int>, ISoftDelete, IMultiTenant
{
public string Name { get; set; }
public bool IsDeleted { get; set; }
public string? TenantId { get; set; }
}
Reads automatically exclude soft-deleted records and scope to the current tenant:
// Both filters applied transparently — only active customers for the current tenant
var customers = await _customerRepo.FindAsync(c => c.Name.StartsWith("A"));
Writes automatically stamp the tenant and support logical deletion:
// TenantId stamped automatically from ITenantIdAccessor
await _customerRepo.AddAsync(new Customer { Name = "Acme" });
// Soft delete — sets IsDeleted = true, performs UPDATE via EF Core
await _customerRepo.DeleteAsync(customer, isSoftDelete: true);
| Type | Description |
|---|---|
EFCoreRepository<TEntity> | Concrete repository backed by EF Core with full CRUD, LINQ, eager loading, and change tracking |
RCommonDbContext | Abstract DbContext base class implementing IDataStore for named data store resolution |
EFCorePerisistenceBuilder | Fluent builder for registering EF Core DbContexts and repository services in DI |
IEFCorePersistenceBuilder | Builder interface exposing AddDbContext<T>() for registering named DbContexts |
For full documentation, visit rcommon.com.
Licensed under the Apache License, Version 2.0.