TeymurDevv.UnitOfWorkPlus 1.0.4

dotnet add package TeymurDevv.UnitOfWorkPlus --version 1.0.4
                    
NuGet\Install-Package TeymurDevv.UnitOfWorkPlus -Version 1.0.4
                    
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="TeymurDevv.UnitOfWorkPlus" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TeymurDevv.UnitOfWorkPlus" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="TeymurDevv.UnitOfWorkPlus" />
                    
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 TeymurDevv.UnitOfWorkPlus --version 1.0.4
                    
#r "nuget: TeymurDevv.UnitOfWorkPlus, 1.0.4"
                    
#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 TeymurDevv.UnitOfWorkPlus@1.0.4
                    
#: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=TeymurDevv.UnitOfWorkPlus&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=TeymurDevv.UnitOfWorkPlus&version=1.0.4
                    
Install as a Cake Tool

TeymurDevv.UnitOfWorkPlus - Usage Guide

Introduction

TeymurDevv.UnitOfWorkPlus is a powerful .NET package that provides an automated Unit of Work and Repository Pattern implementation. This package allows developers to:

  • Define custom repositories without manually registering them.
  • Use IUnitOfWork to access repositories dynamically as properties.
  • Reduce boilerplate code while maintaining a clean and maintainable architecture.

This guide will walk you through the installation, setup, and usage of TeymurDevv.UnitOfWorkPlus in your .NET project.


📌 Installation

To install the package, run the following command in your .NET project:

 dotnet add package TeymurDevv.UnitOfWorkPlus

Or install via NuGet Package Manager in Visual Studio.


📌 Package Setup

1. Define Your DbContext

Ensure your project has a DbContext to manage database interactions.

using Microsoft.EntityFrameworkCore;

namespace YourProject.Data
{
    public class MyDbContext : DbContext
    {
        public DbSet<Product> Products { get; set; }

        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }
    }
}

2. Configure the Package in Program.cs

Register TeymurDevv.UnitOfWorkPlus services in Program.cs.

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using TeymurDevv.UnitOfWorkPlus.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Register DbContext
builder.Services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer("YourConnectionString"));

// Register UnitOfWork and Repositories
builder.Services.AddUnitOfWork<MyDbContext>(typeof(MyDbContext).Assembly);

var app = builder.Build();
app.Run();

📌 Implementing Custom Repositories

1. Create a Model Class

Define an entity class that represents a database table.

using System.ComponentModel.DataAnnotations;

namespace YourProject.Models
{
    public class Product
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
    }
}

2. Create a Custom Repository

Your repository should implement IRepository<T> from the package.

using YourProject.Models;
using TeymurDevv.UnitOfWorkPlus.Repositories;

namespace YourProject.Repositories
{
    public interface IProductRepository : IRepository<Product>
    {
        Task<Product?> GetByNameAsync(string name);
    }

    public class ProductRepository : Repository<Product>, IProductRepository
    {
        public ProductRepository(DbContext context) : base(context) { }

        public async Task<Product?> GetByNameAsync(string name)
        {
            return await _dbSet.FirstOrDefaultAsync(p => p.Name == name);
        }
    }
}

📌 Using UnitOfWork in Your Application

1. Injecting UnitOfWork in a Controller

using Microsoft.AspNetCore.Mvc;
using TeymurDevv.UnitOfWorkPlus.UnitOfWork;
using YourProject.Repositories;

namespace YourProject.Controllers
{
    [ApiController]
    [Route("api/products")]
    public class ProductController : ControllerBase
    {
        private readonly IUnitOfWork _unitOfWork;

        public ProductController(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        [HttpGet]
        public async Task<IActionResult> GetProducts()
        {
            var products = await _unitOfWork.GetRepository<IProductRepository>().GetAllAsync();
            return Ok(products);
        }
    }
}

📌 Key Features

  • Automatic Repository Discovery: No need to manually register repositories.
  • Unit of Work Pattern: Ensures transactions and proper resource management.
  • Dynamic Repository Access: Access repositories as properties inside IUnitOfWork.

📌 Additional Configuration

Enabling Logging for Debugging

If you want to log repository activity, configure logging inside Program.cs:

builder.Services.AddLogging(logging =>
{
    logging.AddConsole();
});

📌 Conclusion

With TeymurDevv.UnitOfWorkPlus, developers can manage repositories effortlessly, ensuring a clean and maintainable architecture. By following this guide, you now have:

✅ Automatic repository discovery and registration ✅ Clean Unit of Work pattern integration ✅ Minimal configuration needed to get started

🚀 Now you are ready to build scalable applications with TeymurDevv.UnitOfWorkPlus! 🚀

Product 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. 
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.0.4 121 2/26/2025
1.0.3 112 2/25/2025
1.0.2 108 2/25/2025
1.0.1 111 2/25/2025
1.0.0 115 2/25/2025