Zentient.Repository
1.0.0-beta
See the version list below for details.
dotnet add package Zentient.Repository --version 1.0.0-beta
NuGet\Install-Package Zentient.Repository -Version 1.0.0-beta
<PackageReference Include="Zentient.Repository" Version="1.0.0-beta" />
<PackageVersion Include="Zentient.Repository" Version="1.0.0-beta" />
<PackageReference Include="Zentient.Repository" />
paket add Zentient.Repository --version 1.0.0-beta
#r "nuget: Zentient.Repository, 1.0.0-beta"
#:package Zentient.Repository@1.0.0-beta
#addin nuget:?package=Zentient.Repository&version=1.0.0-beta&prerelease
#tool nuget:?package=Zentient.Repository&version=1.0.0-beta&prerelease
Zentient.Repository API Documentation
Zentient.Repository is a generic repository and unit of work pattern implementation for Entity Framework Core, part of the Zentient Framework. It provides a set of methods for managing the overall data access and transactional behavior of an application.
Getting Started
To use Zentient.Repository, first install the NuGet package in your project:
Install-Package Zentient.Repository
Then, create a new class that inherits from Repository<T> and IRepository<T>:
public class MyService
{
private readonly IRepository<MyEntity> _repository;
public MyService(IRepository<MyEntity> repository)
{
_repository = repository;
}
public async Task<IEnumerable<MyEntity>> GetAllAsync()
{
return await _repository.GetAllAsync();
}
}
Finally, inject the repository into your service or controller:
services.AddScoped<IRepository<MyEntity>, Repository<MyEntity>>();
In this example, MyEntity is a class that represents a database entity. The MyService class contains a method that retrieves all entities from the database using the repository. The repository is injected into the service using dependency injection.
Features
- Generic Repository: Provides a generic repository implementation for Entity Framework Core.
- Unit of Work: Implements the unit of work pattern to manage transactions and data access.
- Asynchronous Methods: Supports asynchronous methods for improved performance and scalability.
- Dependency Injection: Integrates with the ASP.NET Core dependency injection system for easy configuration and usage.
- Exception Handling Delegate: Allows custom exception handling logic to be defined for database operations.
Usage
The following example demonstrates how to use the repository to use the units of work pattern:
public class MyService
{
private readonly IUnitOfWork _unitOfWork;
public MyService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
// generate some interesting sample code that makes use of the unit of work pattern with multiple repositories
public async Task DoSomethingAsync()
{
using (var transaction = _unitOfWork.BeginTransaction())
{
try
{
var entity1 = new MyEntity { Name = "Entity 1" };
var entity2 = new MyEntity { Name = "Entity 2" };
_unitOfWork.Repository<MyEntity>().AddRangeAsync(new[] { entity1, entity2 });
var entity3 = new MyOtherEntity { Name = "Entity 3", Description = "Description of Entity 3" };
_unitOfWork.Repository<MyOtherEntity>().AddAsync(entity3);
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
throw;
}
}
}
}
In this example, the MyService class contains a method that demonstrates how to use the unit of work pattern with multiple repositories. The DoSomethingAsync method creates new entities and adds them to the repositories using the unit of work. If an exception occurs during the operation, the transaction is rolled back to maintain data consistency.
License
Zentient.Repository is licensed under the MIT License. See the LICENSE file for more information.
Contributing
We welcome contributions to Zentient.Repository! Please see our contributing guide for more information.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.6)
- Microsoft.EntityFrameworkCore.InMemory (>= 8.0.6)
- Newtonsoft.Json (>= 13.0.3)
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 | |
|---|---|---|---|
| 1.2.2-beta | 185 | 6/17/2024 | |
| 1.2.1-beta | 125 | 6/17/2024 | |
| 1.1.0-beta | 145 | 6/6/2024 | |
| 1.0.0-beta | 134 | 6/4/2024 |