![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
a service registry for dependency injection and application composition
const nali = require('nali')
// we can register services
// type Service: (...) => Instance
// Services are functions with
// optional dependency names as parameters
// and which return an initialized instance of itself
// the return value can be a Promise or a Value
nali.register({
config: function () {
return P
conn_str: 'http://foo.bar'
},
db: function (config) {
return Doodaboos.connect(config.conn_str)
})
// we can resolve an instance of our `db` service:
nali.resolve('db').then(function (db) {
// now we can do stuff with our db service
})
nali will fetch or lazily instantiate arbitrary trees of service dependencies.
nali(name: String) => service:any
(alias: nali.fetch
)
Synchronously fetch a service instance
Can also be used to asynchronously resolve multiple dependencies, for example:
nali(function (db, log, sessions, webService) {
// now we have all the things
})
nali.resolve(name: String) => Promise<service: Any>
Asynchronously resolve an instance of a service, lazily instantiating any dependencies if necessary
nali.registerInstance(name: String, instance: Object) => void
deprecated use nali.register('name', () => instance)
instead
nali.registerService(name: String, service: Service) => void
deprecated use nali.register('name', service)
instead
DI works similar to Angular. Service init functions state the names of their dependencies as parameter names, which are parsed out when the Service is registered. They are not called with new
or with any particular this
context.
Return a Promises/A+ promise if you need to asynchronously instantiate a service
Work in progress.
Try get local instance Try get new instance of local service Try get parent instance Try get new instance of parent service Etc
$ npm install nali
From package root:
$ npm install
$ npm test
MIT. (c) MMXV AgileMD. See LICENSE.md
FAQs
a DI service registry
The npm package nali receives a total of 0 weekly downloads. As such, nali popularity was classified as not popular.
We found that nali demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.