# Overriding Existing Methods

As you can see in standard implementation, all methods are marked as virtual which means you can customize their content via overriding them.

You can override the existing methods to create a new class. To do that, newly created classes should inherit from _**RENRepository**_ class:

```csharp
public class MyRepository<TEntity> : RENRepository<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 implementations
        return base.GetSingleAsync(filter, null, include, isReadOnly, cancellationToken);
    }
}
```

Here, we overrided the existing method to expand it's functionality. From now on, we don't have register _**MyRepository**_ in **Program.cs** since we will use it in our UnitOfWork class.&#x20;

In Program.cs you must register it with _**IRENUnitOfWork**_ since we are not using custom Interface here:

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

To achieve this we can create new function named _**GetMyRepository**_ in our UnitOfWork:

```csharp
public class MyUnitOfWork<TDbContext> : RENUnitOfWork<TDbContext> where TDbContext : RENDbContext
{
    public MyUnitOfWork(TDbContext context) : base(context) { }
    
    public override IRENRepository<TEntity>? GetRENRepository<TEntity>()
    {
        return (IRENRepository<TEntity>?)Activator.CreateInstance(typeof(MyRepository<TEntity>), new object[] { _context });
    }
}
```

From now on _**GetMyRepository**_ function returns _**IMyRepository**_ object which contains our custom implementation.

{% hint style="info" %}
You can implement custom function instead of overriding existing one to get repository and use it. It is all up to you!
{% endhint %}

And you can get and use your custom repository like this:

<pre class="language-csharp"><code class="lang-csharp">public class HomeController : ControllerBase
{
    private readonly IRENUnitOfWork&#x3C;RENDbContext> _uow;
<strong>    private readonly IRENRepository&#x3C;Side> _customSideRepository;
</strong><strong>    
</strong><strong>    public HomeController(IRENUnitOfWork&#x3C;RENDbContext> uow)
</strong>    {
        _uow = uow;
        _customSideRepository = _uow.GetRENRepository&#x3C;Side>();
    }
    
    [HttpGet, Route("Index")]
    public async Task&#x3C;IActionResult> Index()
    {
        var side = await _customSideRepository.GetSingleAsync(_=>_.Id == 1);
        return Ok(side);
    }
}
</code></pre>
