I have the following domain object:
public class Bank : IEntity
{
}
And the following IRepository:
public interface IRepository<TEntity> where TEntity : IEntity
{
}
Is the where TEntity : IEntity needed? What does this mean, that TEntity is of type IEntity? Is there any naming conventions when I use something like TEntity? What does the T stand for?
Your
IRepositoryis a generic class and theTEntityis the generic type parameter. It’s like a placeholder for the actual type.TEntity: IEntitymeans that you will require that the actual type being used implementsIEntityand in your actual repository implementation you can refer to methods and properties exposed by the interfaceIEntity.Whether or not it is needed depends on the intended usage of the repository. Usually type restrictions are used to enforce certain properties of the types being used on which the implementation of the generic relies on.