Interested in practices for implementing a layer between the controller and the business service.
public class Controller {
public Response1 test1(Request1 request1){
ServiceInputDto1 serviceInputDto1 = mapper.map(request1, ServiceInputDto1.class);
ServiceOutputDto1 serviceOutputDto1 = service1.test(serviceInputDto1);
Response1 response1 = mapper.map(serviceOutputDto1, Response1.class);
return response1;
}
public Response2 test2(Request2 request2){
ServiceInputDto2 serviceInputDto2 = mapper.map(request2, ServiceInputDto2.class);
ServiceOutputDto2 serviceOutputDto2 = service2.test(serviceInputDto2);
Response2 response2 = mapper.map(serviceOutputDto2, Response2.class);
return response2;
}
}
Following the example above, it seems worth separating the mapping and calling business services from the controller. I suppose that it will have a dto mapping, some initial validation of the input data and a call to the business service.
- Is it correct in such cases to put it in a separate layer at all?
- What design pattern can this layer be considered to be?
- Is it worth it to combine all calls to business services into one layer (one class)?
In my practice, there was a facade (as a design pattern), but it seems there is a more precise definition of what I want.
Aucun commentaire:
Enregistrer un commentaire