Add ObjectFactory as a service
ObjectFactory exists to handle lazy instantiation of objects based on
declarative specifications.
One drawback to the current use of static ObjectFactory::getObjectFromSpec()
is that it doesn't have a good way to handle dependency injection. The
best you could do is refer to a static 'factory' function in your
specification, and that function would access the global service
container. But DI would prefer not to have that "global service
container" being accessed.
The solution is to have a non-static ObjectFactory that can supply
the needed services based on the object definition. For example,
[
'class' => MyObject::class,
'services' => [ 'FooFactory', 'BarFactory' ],
]
would get the FooFactory and BarFactory from a service container to pass
into MyObject's constructor.
But in order for that to be possible, you need to have an instance of
ObjectFactory that has reference to the service container from which to
fetch the services. And the most DI-correct way to get that is to have
it dependency-injected into your constructor, at which point the
ObjectFactory instance should itself be a service in the DI service
container.
Bug: T222409
Change-Id: I2a56059a9209abce0b22fb93c9f9c6a09a825c56