Dependency Injection with RequireJS

前端 未结 3 997
野性不改
野性不改 2020-12-04 10:38

How much can I stretch RequireJS to provide dependency injection for my app? As an example, let\'s say I have a model that I want to be a singleton. Not a singleton in a s

3条回答
  •  渐次进展
    2020-12-04 11:09

    If you're serious about DI / IOC, you might be interested in wire.js: https://github.com/cujojs/wire

    We use a combination of service relocation (like Domenic describes, but using curl.js instead of RequireJS) and DI (using wire.js). Service relocation comes in very handy when using mock objects in test harnesses. DI seems the best choice for most other use cases.

提交回复
热议问题