The Factory's responsibility is to orchestrate the different classes, and it's dependencies (through Dependency Provider or Config).
The Factory class creates the classes of your logic and its dependencies. They are provided to the Facade. It's a layer between the user and your domain.
Creating your objects
The Factory is the place where you create your domain services and objects. It is accessible only by the Facade.
Autowiring dependencies into the Factory
Gacela can resolve automagically the dependencies for the Factory. If the dependency is a concrete class it will create a new instance of it recursively with their inner dependencies as well. But, if the dependency is an interface, then the way to tell Gacela which instante do you want to create you need to create a map between the interface and the concrete class or object that you want to use.
This map will be created in the
gacela.php config file. For example
The major difference between these two are
InterfaceToConcreteClasswill be resolved by creating an instance of that
ConcreteClasson the fly (even using auto-wiring for its dependencies recursively if needed).
InterfaceToCallablewon't create a new instance, but instead it will use the instance that you might want to.
Injecting global services to Gacela config
You can let know Gacela the global services that you want to have access in your
gacela.php config file
by passing them in the entry point of your app:
this way you have access now to the global services, in this case the symfony kernel, so you can map the EntityManagerInterface to the one that the symfony.kernel.container itself already created:
To see the complete example, please check out this repository.