Using REN.Kit’s Built-in Unit Of Work

The easiest way to achieve robust, maintainable data access in your .NET applications is by leveraging REN.Kit’s built-in Unit of Work and Repository services. No custom infrastructure, no ceremony—just reliable, out-of-the-box database operations.


How to Use the Built-In Unit of Work and Repository

Once you’ve configured and registered the DataKit services (see previous setup sections), you’re ready to inject the IRENUnitOfWork into any controller, service, or business class, and start handling your database operations in a safe, transactional manner.

[Route("api/[controller]")]
[ApiController]
public class StandardDataController(IRENUnitOfWork<AppDbContext> unitOfWork) : ControllerBase
{
    /// <summary>
    /// Gets all departments with their employees.
    /// </summary>
    [HttpGet("departments")]
    public async Task<IActionResult> GetDepartments()
    {
        var departments = await unitOfWork.GetRepository<Department>()
            .GetListAsync(include: q => q.Include(d => d.Employees));
        return Ok(departments);
    }

    /// <summary>
    /// Inserts a new employee.
    /// </summary>
    [HttpPost("employees")]
    public async Task<IActionResult> AddEmployee([FromBody] Employee employee)
    {
        unitOfWork.GetRepository<Employee>().Insert(employee);
        await unitOfWork.SaveChangesAsync();
        return Ok("Employee added.");
    }
}

Supported Operations

With REN.Kit DataKit’s standard Unit of Work and Repository implementation, you can:

  • Query any entity using LINQ, with full support for Include, filters, ordering, and projections.

  • Add, update, and delete entities, both individually or in bulk.

  • Count and check for existence of entities using built-in Count, CountAsync, Exists, and Any methods.

  • Perform all operations synchronously or asynchronously.

  • Group multiple database operations inside an explicit transaction, or just rely on implicit transactions for each SaveChanges.

That’s it!

For most .NET applications, this is all you need for safe, high-performance, and maintainable data access. If you need more, REN.Kit DataKit is fully extensible—override or extend repositories, customize Unit of Work, or plug in your own business logic.

Last updated