Muslim.GenericRepository.Interface
10.0.1
dotnet add package Muslim.GenericRepository.Interface --version 10.0.1
NuGet\Install-Package Muslim.GenericRepository.Interface -Version 10.0.1
<PackageReference Include="Muslim.GenericRepository.Interface" Version="10.0.1" />
<PackageVersion Include="Muslim.GenericRepository.Interface" Version="10.0.1" />
<PackageReference Include="Muslim.GenericRepository.Interface" />
paket add Muslim.GenericRepository.Interface --version 10.0.1
#r "nuget: Muslim.GenericRepository.Interface, 10.0.1"
#:package Muslim.GenericRepository.Interface@10.0.1
#addin nuget:?package=Muslim.GenericRepository.Interface&version=10.0.1
#tool nuget:?package=Muslim.GenericRepository.Interface&version=10.0.1
Muslim.GenericRepository.Interface
The repository interfaces only: IRepository<TEntity> and the interfaces it is built from — reads,
writes, soft delete, bulk operations, counts, raw SQL and save. No EF Core implementation.
dotnet add package Muslim.GenericRepository.Interface
Use this package in projects that should depend on the contract only, such as a Domain or Application project. For a working repository, install Muslim.GenericRepository instead — it brings this package with it.
Quick start
In the Application project, declare the repository and use it:
using Muslim.GenericRepository.Interface;
public interface IProductRepository : IRepository<Product> { }
public class ProductService(IProductRepository products)
{
public Task<List<Product>> GetCheapAsync()
=> products.FindAsync(x => x.Price < 10, isTracking: false);
public async Task RenameAsync(int id, string name)
{
var product = await products.GetByIdAsync(id);
product.Name = name;
await products.SaveUpdateAsync(product);
}
}
In the Data project, which references Muslim.GenericRepository, supply the class:
using Muslim.GenericRepository.Repositories;
internal class ProductRepository : Repository<Product>, IProductRepository { }
The Application project never sees EF Core.
Namespaces
IRepository<T> and the interfaces it is built from are in different namespaces. Import both:
using Muslim.GenericRepository.Interface; // IRepository<T>
using Muslim.IGenericRepository; // ICreate<T>, IFind<T>, IDelete<T>, ...
What IRepository includes
IRepository<TEntity> works with any TEntity that inherits Entity from
Muslim.EntityAndDto.
| Interface | Covers |
|---|---|
IGetById<T> |
find by primary key, as an entity or a DTO |
IGetAll<T> |
read the whole table |
IFind<T> |
read by condition, or by an IFilter<T> for grids with paging, sorting and search |
IFirstOrDefault<T> |
the first match, or null |
ISingleOrDefault<T> |
the only match; throws if there is more than one |
ICreate<T> |
insert, from an entity or a DTO |
IUpdate<T> |
update, keeping the audit columns from the database |
IDelete<T> |
delete, including bulk DeleteWhereAsync |
ISoftDelete<T> |
soft delete and restore, including bulk |
IEntityState<T> |
change-tracker access: detach, set state |
ICount<T> / IAny<T> |
counts and "does any row exist" checks |
ISqlOperations<T> |
raw and interpolated SQL |
ISave<T> |
save staged changes |
Query and QueryAsNoTracking give you the IQueryable for anything else.
Rules every implementation follows
Createadds the change,SaveCreateadds it and saves. The same goes for update, delete and soft delete. Use the first form when several changes must be saved together.- The implementation fills the audit columns:
CreatedByandCreatedDateon insert,UpdateByandUpdateDateon update,IsDeleted,DeletedByandDeletedDateon soft delete. All dates are UTC. - Reads that return entities take
isTracking,trueby default. Reads that return a DTO are never tracked. - Bulk methods (
*WhereAsync,*ByIdsAsync) run one SQL statement and need noSave(). They do not load rows, so the change tracker never sees them.
Every member has XML documentation with an example, so your IDE shows it on hover.
Related packages
| Package | Use it for |
|---|---|
| Muslim.EntityAndDto | Base entity and DTO classes |
| Muslim.Filter | Filtering, sorting and paging |
| Muslim.Inject | Automatic dependency registration |
License
See LICENSE.txt.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- Microsoft.EntityFrameworkCore (>= 10.0.13)
- Muslim.EntityAndDto (>= 10.0.1)
- Muslim.Filter (>= 10.0.1)
- Muslim.Inject (>= 10.0.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Muslim.GenericRepository.Interface:
| Package | Downloads |
|---|---|
|
Muslim.GenericRepository
EF Core repository for entities with audit columns: reads, writes, soft delete, bulk operations and raw SQL, with CreatedBy/UpdateBy/DeletedBy and UTC timestamps written automatically. Implements Muslim.GenericRepository.Interface. |
|
|
Muslim.GenericService
Generic CRUD service over Muslim.GenericRepository.Interface: Service<TEntity> implements IService<TEntity> (Muslim.GenericService.Interface) and wraps every repository read, write, soft delete, bulk operation and count, validate DTOs with Muslim.Validator, and return Muslim.Result Result<T> instead of throwing. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Documentation only; no member changed. Corrects XML examples for Find(condition, selector) and the FirstOrDefault/SingleOrDefault<TMap> pairs that failed to compile with CS0121 (type the lambda parameter), and documents the Muslim.GenericRepository 10.0.1 update behavior (stale tracked copies are released; IgnoreUpdateProperty stamps audit columns). See CHANGELOG.md.