-
Notifications
You must be signed in to change notification settings - Fork 2
IRepository
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).
Contains the minimum requirements for a data repository
| Name | Description |
|---|---|
| Initialized | Gets whether the repository is initialized or not |
| ImplementedInterface | Gets the type of the implemented repository interface |
| Name | Description |
|---|---|
| Initialize(IRepositoryManager,IObjectMapper,Type) | Do the required initialization for the repository. |
Extends the IRepository interface and contains an indexer to retrieve an item by its key.
| 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) |
| Name | Description |
|---|---|
| Item[TKey] | Gets the element with the specified key |
Extends the IIndexedRepository interface and defines the functionality for reading all items in the repository
| 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) |
| Name | Description |
|---|---|
| GetItems | Returns all the items in the repository |
Extends the IReadOnlyRepository interface and defines the functionality for CURD operations(Create,Update,Retrieve,Delete)
| 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) |
| 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>
{
}