How to configure DataObject as a Service?

Is it possible to use DataObjects as a Service? I want to use Dependency Injection in my DataObjects __constructor methods but it seems like there is no way to tell pimcore to load my DataObject out of the di-container.

I´ve overriden my model like this (https://pimcore.com/docs/5.x/Development_Documentation/Extending_Pimcore/Overriding_Models.html) and registered it as a service but when i try to inject dependencies i still get errors :confused:

Do you guys have any idea how to fix this?

That is considered an anti pattern, use services elsewhere and pass the dataobject as an argument

ok maybe it helps to add some background-information. all i want to do is add a little helper function the the dataobject class which generates some json-ld tags. i think the object is the perfect place for that. the only reason why i need di is cause i want to inject url generator service to generate the urls the the object used in the json ld tag…

Where do you need json-ld tags? Controller, Views?

Controller: inject the Tag Generator service

Views: create a template helper, inject the tag generator service and use the view helper. (Eg twig extension)

Hi Dominik and thank for your reply. Since i need the tags in the view i´ll try it with a twig extension. Thanks for your help!