jaredhanson / electrolyte

Elegant dependency injection for Node.js.
MIT License
564 stars 61 forks source link

Provide a container factory rather than an immediate global container #13

Open neverfox opened 9 years ago

neverfox commented 9 years ago

I've been running into an issue with electrolyte where the fact that it operates as a global container (cached by node once required) makes it problematic to use when you have one electrolyte project using another electrolyte library as a dependency (since node doesn't guarantee that your dependency won't just use a higher level electrolyte in node_modules). So I get collisions on component names, which silently override the earlier ones. It also makes testing harder because I cannot create isolated containers for a given test suite.

jsumners commented 9 years ago

I think being able to add a namespace to the container would solve the problem. Maybe when you require Electrolyte you could specify the name of the container you want to retrieve?