{"id":18687332,"url":"https://github.com/junosuarez/nali","last_synced_at":"2025-11-08T02:30:32.008Z","repository":{"id":9842180,"uuid":"11833547","full_name":"junosuarez/nali","owner":"junosuarez","description":"npm module: a DI service registry","archived":false,"fork":false,"pushed_at":"2015-11-12T04:43:11.000Z","size":240,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-15T16:46:19.440Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junosuarez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-02T02:56:36.000Z","updated_at":"2015-04-23T18:30:10.000Z","dependencies_parsed_at":"2022-09-07T13:41:22.149Z","dependency_job_id":null,"html_url":"https://github.com/junosuarez/nali","commit_stats":null,"previous_names":["jden/nali"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fnali","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fnali/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fnali/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junosuarez%2Fnali/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junosuarez","download_url":"https://codeload.github.com/junosuarez/nali/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239545350,"owners_count":19656765,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T10:32:29.533Z","updated_at":"2025-11-08T02:30:31.952Z","avatar_url":"https://github.com/junosuarez.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nali\na service registry for dependency injection and application composition\n\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n[![Dependency Status](https://david-dm.org/jden/nali.svg)](https://david-dm.org/jden/nali) \n[![Circle CI](https://circleci.com/gh/jden/nali.svg?style=svg)](https://circleci.com/gh/jden/nali)\n\n## usage\n```js\nconst nali = require('nali')\n\n// we can register services\n// type Service: (...) =\u003e Instance\n// Services are functions with\n// optional dependency names as parameters\n// and which return an initialized instance of itself\n// the return value can be a Promise or a Value\nnali.register({\n  config: function () {\n    return P\n    conn_str: 'http://foo.bar'\n  },\n  db: function (config) {\n    return Doodaboos.connect(config.conn_str)\n  \n  })\n\n// we can resolve an instance of our `db` service:\n\nnali.resolve('db').then(function (db) {\n  // now we can do stuff with our db service\n})\n\n```\n\nnali will fetch or lazily instantiate arbitrary trees of service dependencies.\n\n## api\n\n### `nali(name: String) =\u003e service:any`\n(alias: `nali.fetch`)\n\nSynchronously fetch a service instance\n\nCan also be used to asynchronously resolve multiple dependencies, for example:\n\n```js\nnali(function (db, log, sessions, webService) {\n  // now we have all the things\n})\n```\n\n### `nali.resolve(name: String) =\u003e Promise\u003cservice: Any\u003e`\nAsynchronously resolve an instance of a service, lazily instantiating any dependencies if necessary\n\n### `nali.registerInstance(name: String, instance: Object) =\u003e void`\n\n*deprecated* use `nali.register('name', () =\u003e instance)` instead\n\n\n### `nali.registerService(name: String, service: Service) =\u003e void`\n*deprecated* use `nali.register('name', service)` instead\n\n## Service Dependencies\n\nDI 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.\n\nReturn a Promises/A+ promise if you need to asynchronously instantiate a service\n\n## Resolution algorithm\n\nWork in progress.\n\nTry get local instance\nTry get new instance of local service\nTry get parent instance\nTry get new instance of parent service\nEtc\n\n## not implemented\n\n- scopes\n- disposing instances / lifecycle management\n- anything else\n\n\n## installation\n\n    $ npm install nali\n\n\n## running the tests\n\nFrom package root:\n\n    $ npm install\n    $ npm test\n\n\n## contributors\n\n- jden \u003cjason@denizac.org\u003e\n\n\n## license\n\nMIT. (c) MMXV AgileMD. See LICENSE.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Fnali","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunosuarez%2Fnali","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunosuarez%2Fnali/lists"}