-2

Is there any possibility to bind Objects into Variable in Symfony 5 using Attributes?

For example, I have class:

class Users 
{
    private $servers; 
}

I has property $servers. I want to bind some object to this class using Attributes with some functionality and validation.

  • You might be asking about [property injection](https://symfony.com/doc/current/service_container/injection_types.html#property-injection). Not sure what `functionality and validation` means in this context. Constructor and setter injection are generally preferred over property injection. – Cerad May 06 '22 at 12:08

1 Answers1

-1

you can do it if you inject it in your constructor like this

services.yaml

services:
  Users:
    arguments:
       $servers: <your value>

And in your Users class

class Users 
{
    private $servers; 

    public function __construct( $servers) 
    {
       $this->servers = $servers
     }
}

R4ncid
  • 6,944
  • 1
  • 4
  • 18