Fosrestbundle: Autowiring in DTO

Created on 25 Jul 2018  路  4Comments  路  Source: FriendsOfSymfony/FOSRestBundle

Body Param converter feature allows us to convert request params into DTO object and perform validation on them
https://symfony.com/doc/master/bundles/FOSRestBundle/request_body_converter_listener.html

There is problem that by default jms serialiser constructs objects on its own, without using autowiring. So only limited number of validators can be used. Unfortunately autowiring of deserialized object is not compatible with JMSserializer principles.

So I wonder if this feature can be implemented within fos-rest-bundle?

https://github.com/schmittjoh/serializer/pull/979

Most helpful comment

I'm wondering why you would want to inject a service into a DTO. That looks like a weird architecture to me.

All 4 comments

I'm wondering why you would want to inject a service into a DTO. That looks like a weird architecture to me.

@stof to perform validation against database for example

I'm wondering why you would want to inject a service into a DTO. That looks like a weird architecture to me.

Otherwise issue exists, class using paramconverter can not autowire service in it

I do not see that this will ever happen inside FOSRestBundle. So I am going to close here.

For validation, you can use the validator service and pass it your DTO. Validation constraints can be registered as services and thus do nearly everything.

Was this page helpful?
0 / 5 - 0 ratings