Using REN.Kit’s Built-in Unit Of Work
How to Use the Built-In Unit of Work and Repository
[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
That’s it!
Last updated