When working on a repository i generaly try to keep the method pretty generic, but this can sometimes lead to calling longer methods, or creating more specificly named methods at the service layer. My question is, how much knowledge of your domain should your a resitory layer have?
For example, I currently have a method as follows:
public User GetUniqueByRoleAndRoleProperty<TRole>(string propertyName, object propertyValue)
{
...
}
Which I use to pull back users with a specific role and property, but would it be giving the repository too much knowledge to have a method such as:
public User GetArtistBySlug(string slug)
{
...
}
It should have enough knowledge to do its work and no more. It's fine to have a lookup for artists by slug if "slug" is an attribute of the "artist" record, because the layer knows that already. If the assignment of slugs to artists follows complex, intricate rules (think heraldry, or something like that), then the repository should not implement those, except if you absolutely have to use clever optimizations that only work on this level, e.g. special database query constructions.
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