I have Domain/Application/Persistance and Api layer architecture.
- Domain lives isolated without any reference to the outside layers
- Application references Domain only
- Persistance and Api layer are on the same level, referencing Application and Domain.
In the following example of api endpoint, where should I put input and output models. Input model as entry point of api endpoint and output model as exit point of api endpoint.
[HttpGet]
public async Task<IActionResult>Get(GetModel model)
{
var queryModel = this.Mapper<QueryModel>(model);
var getCarQuery = this.mediator.Send(queryModel);
}
Handler for this getCarsQuery lives on the Application layer. Inside this handler I use repository in order to get data from the database, here's where I have a dilemma:
Should handler from the Application layer return Dto (also stored in the Application layer) and having no mapping from dto to api response
[HttpGet]
public async Task<IActionResult>Get(GetModel model)
{
var queryModel = this.Mapper<QueryModel>(model);
CarDto getCarQuery = this.mediator.Send(queryModel);
return Ok(getCarQuery);
}
Should handler return Domain object using repository and leave api side to handle mapping of domain object (from handler) to api response (dto)?
[HttpGet]
public async Task<IActionResult>Get(GetModel model)
{
var queryModel = this.Mapper<QueryModel>(model);
Car getCarQuery = this.mediator.Send(queryModel);
CustomApiResponse response = _mapper<CustomApiResponse>(getCarQuery);
return Ok(response);
}
Long story short, in the above architecture where would you put input and output models of the api endpoint and should handler return dto or data models?