IRepository - Aghyad-Khlefawi/Coddee GitHub Wiki

An interface the defines the basic functionality of a data repository. Every repository must implement an interface that defines its functionality, for example if we need a repository that handles the Person objects then we need to define a IPersonRepository then we could have multiple implementation for that repository like a LineToSqlPersonRepository which uses an SQL server database to access the data or a RESTApiPersonRepository which uses a REST Api to access the data. The main idea is to use the interface (IPersonRepository) when working with the repository so the client businesses wont be concerned with how the data is being access and will be able to use the shared functionality that is defined in the interface (IPersonRepository).

Available implementation


IRepository

Contains the minimum requirements for a data repository

Properties

Name Description
Initialized Gets whether the repository is initialized or not
ImplementedInterface Gets the type of the implemented repository interface

Methods

Name Description
Initialize(IRepositoryManager,IObjectMapper,Type) Do the required initialization for the repository.

IIndexedRepository[TModel,TKey]

Extends the IRepository interface and contains an indexer to retrieve an item by its key.

Type parameters

Name Description
TModel The business entity type(This type must implement the IUniqueObject interface)
TKey The key of the primary key for the business entity (The type implemented with the IUniqueObject interface)

Properties

Name Description
Item[TKey] Gets the element with the specified key

IReadOnlyRepository[TModel,TKey]

Extends the IIndexedRepository interface and defines the functionality for reading all items in the repository

Type parameters

Name Description
TModel The business entity type(This type must implement the IUniqueObject interface)
TKey The key of the primary key for the business entity (The type implemented with the IUniqueObject interface)

Methods

Name Description
GetItems Returns all the items in the repository

ICRUDRepository[TModel,TKey]

Extends the IReadOnlyRepository interface and defines the functionality for CURD operations(Create,Update,Retrieve,Delete)

Type parameters

Name Description
TModel The business entity type(This type must implement the IUniqueObject interface)
TKey The key of the primary key for the business entity (The type implemented with the IUniqueObject interface)

Methods

Name Description
UpdateItem(TModel) Updates and items in the repository
InsertItem(TModel) Inserts a new items to the repository
DeleteItem(TModel) Deletes an item from the repository
DeleteItem(TKey) Deletes an item from the repository by it's key

C# Example:

//The data model
public class Person : IUniqueObject<int>
{
    public int ID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int GetKey { get { return ID; } }
}

//Defining the repository interface
public interface IndexedPersonRepository : IIndexedRepository<Person, int>
{
}

public interface IReadOnlyPersonRepository : IReadOnlyRepository<Person, int>
{
}

public interface ICRUDPersonRepository : ICRUDRepository<Person, int>
{
}
⚠️ **GitHub.com Fallback** ⚠️