Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much knowledge of your domain should your repository layer have?

Tags:

c#

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)
{
    ...
}
like image 451
Matt Brailsford Avatar asked Nov 05 '22 16:11

Matt Brailsford


1 Answers

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.

like image 142
Kilian Foth Avatar answered Nov 15 '22 12:11

Kilian Foth