Pendramon
❔ Need Experience Sharing
Another thing that has been pointed out to me is that you should have another set of DTOs in Web API project. The reason being is that Web Api endpoints shouldn't change so you don't break consumers of the web api. If you change a service layer dto it will also change the web api endpoint(for example if you remove some property from the service layer dto).
Another reason is, If all of your endpoint parameters don't come from body, you will need a separate dto for the from body parameter which then inside your endpoint method you would combine the data from the query parameters and the from body dto parameter to a service layer dto.
One more thing I've learned is to always use a DTO for your FromBody parameter. If you use a single value type then the web api request body would be just the value for example int
1
, while if you store that int as a property inside a dto and use that dto as a from body parameter, the request body would look like { "MyIntegerPropertyName": 1 }
. This would allow you to add additional from body parameters if you ever need them in the future and it won't break any existing consumers of your endpoint. It also adds consistency between your web api endpoint request bodies.26 replies
❔ Need Experience Sharing
I'd put auto mapper in CQRSCore. I'll note down however that I've seen a lot of people discourage it and recommend doing the mapping manually. I believe the justification was because its black magic. You are unaware of what it does underneath and can cause problems in the future.
26 replies