I'm pretty new in .Net community, please show mercy haha. I got two questions:

  1. is there any similar implementation of symfony's @paramconverter annotation in ASP.NET (such as a converter attributes)? e.g. the request url, no matter GET/POST/PUT/DELETE, the api request with an id of certain entity and we are able to convert/bind such id into a entity object(say productId in int and convert to Product object)

Expected PseudoCode:

[Route("products/{productId}/comments")]
[ProductConverter]
public HttpResponseMessage getProductComments(Product product) {
    // product here not only with `productId` field, but already converted/bind into `Product`, through repository/data store
    ....
}
  1. Is this good implementation in .Net? I ask for this implementation because I think this pattern able to reduce duplicate code when API requests mainly rely on object id and I able to convert id into an object, before actual use of the object. I can even throw an exception if such Product object not found by such string.

Related posts

Recent Viewed