Lazy loading makes sense for fast startups, but it means that we can't guarantee that any given factory function ever gets called. So, if I'm relying on, for instance, Express routes getting registered, I can't.
Possible options:
Eager-load all functions. Just iterate through the registry after the bind function. This has the added benefit of identifying missed bindings up front.
Create a module.start() kinda function that does the above.
Create an alternate to bind() (bindAndCreate()?) that will mark the binding for eager loading. Or extend the binding vocabulary to be something like (bind(...).toFactory(...).andEagerLoad()). I kinda like the previous option better because it would be easier to scan through and see what is simply bound and what is set to be initialized.
This is a toughy.
Lazy loading makes sense for fast startups, but it means that we can't guarantee that any given factory function ever gets called. So, if I'm relying on, for instance, Express routes getting registered, I can't.
Possible options:
module.start()
kinda function that does the above.bind()
(bindAndCreate()
?) that will mark the binding for eager loading. Or extend the binding vocabulary to be something like (bind(...).toFactory(...).andEagerLoad()
). I kinda like the previous option better because it would be easier to scan through and see what is simply bound and what is set to be initialized.