I'm new to design patterns and specifically the Service Layer implementation. I need some clarification on where to use Service Layer calls.
Below is an example of what I'm dealing with. I have data from 2 different repositories so I'm not quite certain when/where I'm supposed to call up any additional information that I need to build my Business Model.
I would like for it to do the following:
- Find Car in Repository
- Get Picture from another Repository
- Update Url within Model to be used for Presentation Layer.
What i'm stuck with is I'm not sure if that logic belongs in the Car Model or it should be handled by a Service layer and within the service layer all of this gets combined. Hopefully this isn't too confusing. Below I added what I thought was relevant.
Business Model/Logic:
public class Car
{
private readonly IFileSystemService _service;
public Car(IFileSystemService service)
{
_service = service;
}
public int id { get; set; }
public string model { get; set; }
public int year { get; set; }
public Image GetImageFile(IGetImageService imgService);
}
Within the Service Layer:
public void GetImageFile(int carId)
{
Image imgfile = _Repository.GetPhysicalFileLocation(carId);
// ...
}
Repository 1:
public Car GetCar(int carId)
{
Car myCar = this.GetCar(carId);
// ...
}
Repository 2:
public Car GetPictureForCar(int carId)
{
Car myCar = this.GetFileForCar(carId);
// ...
}