Question

I need some advice on where to draw the line with my services and repositories.

public class Contact
{
     public Guid Id {get;set;}
     public string Username {get;set;}
     public Guid? AvatarId {get;set;}
     public Avatar Avatar {get;set;}
}

public class Avatar
{
     public Guid Id {get;set;}
     public string FullSizeImagePath {get;set;}
     public string ThumbnailSizeImagePath {get;set;}
}

Let's assume the Avatar model will only be used on a Contact model and that it is an optional property on the Contact. Should my repository be responsible for adding an Avatar to the contact or should the business / service layer extend that functionality? One can argue that it is a business requirement to have an avatar, but since it is part of the model the data layer should know how to deal with it.

I proposed we could add the functionality to Add / Update and Remove an avatar via the repository. The Business / Service layer would be responsible for saving the physical files, validation, and calling the appropriate methods on the repository. All the repository cares about is attaching the appropriate contact and adding an avatar to it.

my thought process was that since an avatar is only being used on a Contact, currently, we would extend the repository and thus add functionality to the DAL. This might be useful for a separate API.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top