ecowden / pluto.js

JavaScript Dependency Injection
MIT License
8 stars 3 forks source link

Eager Loading #14

Closed ecowden closed 11 years ago

ecowden commented 11 years ago

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:

  1. Eager-load all functions. Just iterate through the registry after the bind function. This has the added benefit of identifying missed bindings up front.
  2. Create a module.start() kinda function that does the above.
  3. 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.