# Using Both

To use both you have to combine two methods. First create the _**IMyRepository**_ Interface to implement additional methods:

```csharp
public interface IMyRepository<TEntity> : IRENRepository<TEntity> where TEntity : class
{
    Task MyCustomFunction(CancellationToken cancellationToken = default);
}
```

Then create _**MyRepository**_ class that inherits from _**RENRepository**_ and  _**IMyRepository**_ and contains overriden method(s):

```csharp
public class MyRepository<TEntity> : RENRepository<TEntity>, IMyRepository<TEntity> where TEntity : class
{
    public MyRepository(RENDbContext context) : base(context) { }

    public override Task<TEntity?> GetSingleAsync(Expression<Func<TEntity, bool>> filter,
        Expression<Func<IQueryable<TEntity>, IQueryable<TEntity>>>? include = null,
        bool isReadOnly = false,
        CancellationToken cancellationToken = default)
    {
        Console.WriteLine("Getting custom async......");
        // Other custom implementations
        return base.GetSingleAsync(filter, null, include, isReadOnly, cancellationToken);
    }

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

        }, cancellationToken);
    }
}
```

To use _**MyRepository**_ class with the interface, we created _**IMyRepository**_ interface. We need to add a repository getter function to get repositories in _**IMyRepository**_ type instead of _**IRENRepository.**_ We need that because _**IRENRepository**_ does not contain our custom function!

```csharp
public interface IMyUnitOfWork<TDbContext>: IRENUnitOfWork<TDbContext> where TDbContext : RENDbContext
{
    IMyRepository<TEntity>? GetMyRepository<TEntity>() where TEntity : class;
}
```

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

    public IMyRepository<TEntity>? GetMyRepository<TEntity>() where TEntity: class
    {
        return (IMyRepository<TEntity>?)Activator.CreateInstance(typeof(MyRepository<TEntity>), new object[] { _context });
    }
}
```

In _**Program.cs**_ we need to register _**MyUnitOfWork**_ class from interface _**IMyUnitOfWork**_ since it contains the repository getter method.

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

Then you can use your final Repository and Unit Of Work classes like this:

```csharp
public class HomeController : ControllerBase
{
    private readonly IMyRepository<User> _customUserRepository;
    private readonly ICacheService _cacheService;

    public HomeController(IMyUnitOfWork<RENDbContext> uow)
    {
        _customUserRepository = uow.GetMyRepository<User>();
    }

    [HttpGet, Route("Index")]
    public async Task<IActionResult> Index()
    {
        await _customUserRepository.MyCustomFunction(); // our custom function
        await _customUserRepository.GetSingleAsync(_ => _.Id == 1); // our overriden function
        return Ok();
    }
}
```
