Zentient.Repository 1.0.0-beta

This is a prerelease version of Zentient.Repository.
There is a newer prerelease version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zentient.Repository" Version="1.0.0-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zentient.Repository" Version="1.0.0-beta" />
                    
Directory.Packages.props
<PackageReference Include="Zentient.Repository" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zentient.Repository --version 1.0.0-beta
                    
#r "nuget: Zentient.Repository, 1.0.0-beta"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zentient.Repository@1.0.0-beta
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zentient.Repository&version=1.0.0-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Zentient.Repository&version=1.0.0-beta&prerelease
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2-beta is deprecated because it is no longer maintained.
1.2.1-beta 125 6/17/2024
1.1.0-beta 145 6/6/2024
1.0.0-beta 134 6/4/2024