I started to implement a repository pattern following this tutorial. Now In the definition of the class which implements the interface of Repository. The defines of the classes are made like this.
public class Repository<E,C> : IRepository<E,C>, IDisposable
where E : EntityObject
where C : ObjectContext
{
}
Can someone explain me if I defined a class with generics why do i need to type where to explain which are the objects that are expected??. I’m really confused with this topic
Constraining the types with
whereis a deliberate choice, which has two consequences:EandCasEntityObjectandObjectContextwithin the definition ofRepository<,>; otherwise, it would not let you access members (methods, properties, etc) of those classes because it wouldn’t be able to guarantee that those members exist on the types used to specify the generic.