TeymurDevv.UnitOfWorkPlus
1.0.2
See the version list below for details.
dotnet add package TeymurDevv.UnitOfWorkPlus --version 1.0.2
NuGet\Install-Package TeymurDevv.UnitOfWorkPlus -Version 1.0.2
<PackageReference Include="TeymurDevv.UnitOfWorkPlus" Version="1.0.2" />
<PackageVersion Include="TeymurDevv.UnitOfWorkPlus" Version="1.0.2" />
<PackageReference Include="TeymurDevv.UnitOfWorkPlus" />
paket add TeymurDevv.UnitOfWorkPlus --version 1.0.2
#r "nuget: TeymurDevv.UnitOfWorkPlus, 1.0.2"
#:package TeymurDevv.UnitOfWorkPlus@1.0.2
#addin nuget:?package=TeymurDevv.UnitOfWorkPlus&version=1.0.2
#tool nuget:?package=TeymurDevv.UnitOfWorkPlus&version=1.0.2
UnitOfWorkPlus - Usage Guide
📌 Introduction
UnitOfWorkPlus is a fully automated and dependency injection (DI) friendly implementation of the Unit of Work + Repository Pattern. It allows you to manage repositories dynamically without manually registering them.
🚀 Features
✔ No manual repository registration required
✔ Automatic detection of repositories
✔ Direct repository access via _unitOfWork.ProductRepository
✔ Works seamlessly with Dependency Injection (DI)
✔ Supports dynamic access using _unitOfWork["Product"]
📌 1️⃣ Installation
- Add
UnitOfWorkPlus
package to your project:dotnet add package UnitOfWorkPlus
📌 2️⃣ Setup in Program.cs
Register UnitOfWork and DbContext in Dependency Injection (DI).
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using YourNamespace.Data; // Your ApplicationDbContext
using TeymurDevv.UnitOfWorkPlus;
var builder = WebApplication.CreateBuilder(args);
// Register UnitOfWork and DbContext
builder.Services.AddUnitOfWork<ApplicationDbContext>();
var app = builder.Build();
app.Run();
📌 3️⃣ Inject IUnitOfWork
and Use in a Service
Use IUnitOfWork
in services to access repositories dynamically.
public class ProductService
{
private readonly IUnitOfWork _unitOfWork;
public ProductService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task AddProduct(string name, decimal price)
{
var product = new Product { Name = name, Price = price };
await _unitOfWork.Repository<Product>().Create(product);
await _unitOfWork.SaveChangesAsync();
}
}
📌 4️⃣ Inject IUnitOfWork
in a Controller
Use IUnitOfWork
in an API controller to perform CRUD operations.
[Route("api/[controller]")]
[ApiController]
public class ProductController : ControllerBase
{
private readonly IUnitOfWork _unitOfWork;
public ProductController(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
[HttpPost]
public async Task<IActionResult> AddProduct([FromBody] Product product)
{
await _unitOfWork.Repository<Product>().Create(product);
await _unitOfWork.SaveChangesAsync();
return Ok("Product added successfully.");
}
[HttpGet]
public async Task<ActionResult<List<Product>>> GetProducts()
{
return await _unitOfWork.Repository<Product>().GetAll();
}
}
📌 5️⃣ Dynamic Repository Access
You can dynamically access repositories by entity name.
var productRepo = (IRepository<Product>)_unitOfWork["Product"];
await productRepo.Create(new Product { Name = "Smartphone", Price = 799.99M });
await _unitOfWork.SaveChangesAsync();
🎯 Summary
✔ Automatic repository detection
✔ No need for manual repository registration
✔ Seamless integration with ASP.NET Core
✔ Direct repository access via _unitOfWork.Repository<Product>()
✔ Dynamic repository access via _unitOfWork["Product"]
🚀 Now your UnitOfWork system is fully automated and production-ready! 🔥
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 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. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.EntityFrameworkCore.Abstractions (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.