-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Method initialize()
should be part of DI\Container
life-cycle & interface
#232
Comments
It makes sense. |
Note that |
@JanTvrdik You right. Make autoinvoke this method looks like bad practice. I think about your words, now whole Kua! |
initialize() is not part of the DI container's responsibility and is actually part of the Configurator that calls it. The current form is a big compromise, but very functional and practical. I think the gradual adaptation of this a1b1e94 could be the beginning to replace the initialize() function with something more appropriate. |
Why? Sometimes it is the best to discuss :-) |
If initialize() is replaced by some other form of initialization, please keep it optional. I just found a use case which would be quite hard to test if initialize() was called orisai/nette-http@cc6e686#diff-4c400ef0e67cf26d9094888eff469b5ff8e40233d46419e066ef2117a4361837L51-R72 It was also helpful to allow configurator to not call initialize() orisai/nette-di@76f8caf#diff-3a497e56f0277c5ca4e8660abda9bca83312dfb21948ac71ca91a343c5bf928aL252-R264 |
Some Nette DI extensions are using the container's
initialize()
method to append some logic which must be executed at end of container's setup phase.But
initialize()
is just popular convention, not interface. That produces few problems:initialize()
method is not called automatically before the first use of the container, neither fromDI\ContainerLoader
norDI\Container
internally. The app is here responsible to call this method externally.Container instance is generated at the run-time phase. A developer during developing has no way how to guarantee how the geterated container will look because app can only use
DI\Container
class interface which doesn't containsinitialize()
method (please, let Reflection sleep).That's mean, PhpStorm is yelling inspections the method is undefined.
App never should use anything out of known interface.
That was formally problem, now the serious problem:
Look to two examples of app's
config.neon
files which is usingConstantsExtension
:The first one is create container with
initialize()
method. If the app does not call them, app will be incorrectly booted.The second one is create container without them. If the app try call them, app will be crash info fatal error.
That's create very fragile stability of app design.
My suggestions
initialize()
toDI\Container
to create stable interface.initialize()
. Especially to documentation, because currently is mentioned as optional convention, but actually is it very important milestone.I am happy happy to send PR, but first let me know my idea is valid or not.
Thanks for great tool ❤️
The text was updated successfully, but these errors were encountered: