Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation AoT - factories + injector decorator #2

Open
weierophinney opened this issue Dec 31, 2019 · 2 comments
Open

Documentation AoT - factories + injector decorator #2

weierophinney opened this issue Dec 31, 2019 · 2 comments

Comments

@weierophinney
Copy link
Member

I think the documentation is wrong:
https://docs.zendframework.com/zend-di/cookbook/aot-guide/#5-add-aot-to-the-service-manager

In getDependencies method of ConfigProvider we have:

            'factories' => $this->getGeneratedFactories(),
            'delegators' => [
                InjectorInterface::class => [
                    InjectorDecoratorFactory::class,
                ],
            ],

but I think one of this configuration is useless.
If we inject generated factories in factories key then we don't need to use decorator (which uses GeneratedInjector and in fact is an abstract factory - but uses only generated factories list).

But in case we have factories injected already into service manager the abstract factory for the service is not going to be called as the factory is defined. If the factory is not defined (so for example service was added later and factories were not regenerated) then normal injector is going to be used anyway (generated injector is just the proxy to origin injector in case factory is not defined).

Of course it doesn't change too much, but in case we need use injector (abstract factory) we don't need to check again on generated list, as this is not there.


Originally posted by @michalbundyra at zendframework/zend-di#53

@weierophinney
Copy link
Member Author

This part of the documentation will cover use cases where the Injector or AutowireFactory is used in a custom service factory. When this is done the Injector will perform a runtime injection instead of using an AoT factory.

Example:

class MyServiceFactory
{
    public function __invoke(ContainerInterface $container)
    {
        return (new AutowireFactory())->create($container, MyService::class, [
            'customParam' => 'SomeService',
        ]);
    }
}

I don't like the idea to sacrifice this feature or leave it undocumented. Maybe we should rephrase the docs here


Originally posted by @tux-rampage at zendframework/zend-di#53 (comment)

@weierophinney
Copy link
Member Author

Ok, now I see - after checking the source of AutowireFactory. Yeah, I think it could be rephrased to make it clearer. In general I think it is quite an edge case...


Originally posted by @michalbundyra at zendframework/zend-di#53 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant