# Implementing New Methods

Sometimes your project needs data access operations or utilities that go beyond what the standard Repository provides. Thanks to REN.Kit’s extensible architecture, you can easily add brand new methods to your custom Repository—without altering the base implementation!

***

## How to Extend?

### **1. Create a New Service Interface to Define Your Method**

Define an interface that extends the default Repository interface and adds your new method(s):

```csharp
 public interface IExtendedRENRepository<TEntity> 
      : IRENRepository<TEntity> where TEntity : class
 {
     void AdditionalMethod();
 }
```

This interface introduces your new method(s) while keeping all the standard Repository features.

***

### **2. Create a New Repository Class Implementing the Interface**

Implement your interface by inheriting from `RENRepository<TEntity>` and adding your custom logic:

```csharp
public class ExtendedRENRepository<TEntity>(RenDbContext dbContext) 
    : RENRepository<TEntity>(dbContext), 
    IExtendedRENRepository<TEntity> where TEntity : class
{
    public void AdditionalMethod()
    {
        Console.WriteLine("ExtendedRENRepository AdditionalMethod called.");
        // Implement your additional logic here
    }
}
```

***

### 3. **Register Your Custom Repository**

Although you define and register your custom repository and its interface, **the recommended approach in REN.Kit is&#x20;**_**not**_**&#x20;to inject repositories directly**. Instead, always access your repositories through the Unit of Work instance.

\
This ensures all your data operations—queries, updates, transactions—are tracked, coordinated, and committed consistently.



When requesting a repository from your Unit of Work, specify your custom repository type using the generic overload:

```csharp
private readonly IExtendedRENRepository<Employee> customEmployeeRepository = unitOfWork.GetRepository<ExtendedRENRepository<Employee>, Employee>();
```

This approach ensures that your custom implementation is used for all data access operations involving the specified entity type.

{% hint style="warning" %}
## IMPORTANT!

From this point forward, to access any newly introduced or extended methods, you should obtain your repositories as `IExtendedRENRepository` rather than the standard `IRENRepository`.\
This ensures that you have full access to all the custom logic and features defined in your extended repository interface.
{% endhint %}

***

### **4. Use Your Custom Repository in Action**

```csharp
[Route("api/[controller]")]
[ApiController]
public class ExtendedRepositoryDataController(IRENUnitOfWork<RenDbContext> unitOfWork) : ControllerBase
{
    private readonly IExtendedRENRepository<Employee> customEmployeeRepository = unitOfWork.GetRepository<ExtendedRENRepository<Employee>, Employee>();

    [HttpGet("find")]
    public IActionResult GetRepository(Guid key)
    {
        var employee = customEmployeeRepository.AdditionalMethod();
        return Ok();
    }
}
```

{% hint style="success" %}
## **Pro Tip:**

With this pattern, you get all the power and safety of the standard Repository pattern _plus_ your own custom logic—ideal for project-specific utilities, cross-cutting concerns, or advanced data operations.
{% endhint %}
