Using Both

To use both you have to combine two methods. First create your interface as shown in:

Implementing Additional Methods
public interface IMyUnitOfWork<TDbContext>: IRENUnitOfWork<TDbContext> where TDbContext : RENDbContext
{
    Task MyCustomFunction(CancellationToken cancellationToken = default);
}

Then, create your custom UnitOfWork class that inherits from RENUnitOfWork (since we want to overrride the desired methods and don't want to implement other methods again that IRENUnitOfWork contains) and IMyUnitOfWork (since we want to get newly created custom function signature).

public class MyUnitOfWork<TDbContext> : RENUnitOfWork<TDbContext>, IMyUnitOfWork<TDbContext> where TDbContext : RENDbContext
{
    public MyUnitOfWork(TDbContext context) : base(context) { }

    public Task MyCustomFunction(CancellationToken cancellationToken = default)
    {
        return Task.Factory.StartNew(() =>
        {
            cancellationToken.ThrowIfCancellationRequested();
            Console.WriteLine("This is my custom Function");
            // other custom implementations!
        }, cancellationToken);
    }

    public override Task<bool> SaveChangesAsync()
    {
        Console.WriteLine("This is my custom SaveChangesAsync");
        return base.SaveChangesAsync();
    }
}

In Program.cs you have to register MyUnitOfWork:

builder.Services.AddScoped(typeof(IMyUnitOfWork<>), typeof(MyUnitOfWork<>));

And you can use it like this:

public class HomeController : ControllerBase
{
    private readonly IMyUnitOfWork<RENDbContext> _uow;

    public HomeController(IMyUnitOfWork<RENDbContext> uow)
    {
        _uow = uow;
    }

    [HttpGet, Route("Index")]
    public async Task<IActionResult> Index()
    {
        await _uow.MyCustomFunction();
        return Ok();
    }
        
    [HttpGet, Route("InsertSide")]
    public async Task<ActionResult> InsertSide([FromQuery] string side)
    {
        await _customSideRepository.InsertAsync(new Side()
        {
            Name = side    
        });
            
        await _uow.SaveChangesAsync();
        return Ok();
    }
        
    [HttpGet, Route("InsertUser")]
    public async Task<ActionResult> InsertUser([FromQuery] string name, string surname, int sideId)
    {
        _userRepository.Insert(new User()
        {
            Name = name,
            Surname = surname,
            SideId = sideId
        });
            
        _uow.SaveChanges();
        return Ok();
    }
}

Here, we used both overriden (SaveChangesAsync()) and extra implemented(MyCustomFunction()) functions!

Last updated