we write the code and when we will use generic repo pattern but can anyone explain this convention please? so can anyone explain this code so we can understand how this inheritance works.
public interface IGenericRepository < T > where T: class
This is not inheritance; it is a Type Constraint.
It limits your developers to not use classes in your Generic Repository that are not an actual representation of a DB object.
Imagine, that all your mapped entities implement an Id field of type Guid. You can constraint your repositories to only be usable with objects that have that Id:
public interface IEntity
{
public Guid Id
}
public interface IGenericRepository < T > where T: IEntity
Your Generic Repo will be limited to types which implement that specific interface, and you would be sure that all concrete implementations have Guid Id property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With