{"id":49878915,"url":"https://github.com/arkerone/smart-container","last_synced_at":"2026-05-15T13:13:51.476Z","repository":{"id":57363807,"uuid":"94524792","full_name":"arkerone/smart-container","owner":"arkerone","description":"smart-container is a dependency injection container for NodeJS which can be configured with a configuration file.","archived":false,"fork":false,"pushed_at":"2020-07-21T12:35:07.000Z","size":28,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-05-02T14:33:26.757Z","etag":null,"topics":["container","dependency-injection","helpful","ioc","ioc-container","javascript","nodejs","service"],"latest_commit_sha":null,"homepage":"","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/arkerone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-16T08:49:18.000Z","updated_at":"2019-11-17T21:34:51.000Z","dependencies_parsed_at":"2022-09-16T16:43:55.650Z","dependency_job_id":null,"html_url":"https://github.com/arkerone/smart-container","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/arkerone/smart-container","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkerone%2Fsmart-container","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkerone%2Fsmart-container/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkerone%2Fsmart-container/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkerone%2Fsmart-container/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arkerone","download_url":"https://codeload.github.com/arkerone/smart-container/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkerone%2Fsmart-container/sbom","scorecard":{"id":207254,"data":{"date":"2025-08-11","repo":{"name":"github.com/arkerone/smart-container","commit":"580e189b439af9fed4114d546c8f9fd3a682e69e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T00:03:39.500Z","repository_id":57363807,"created_at":"2025-08-17T00:03:39.500Z","updated_at":"2025-08-17T00:03:39.500Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33067699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["container","dependency-injection","helpful","ioc","ioc-container","javascript","nodejs","service"],"created_at":"2026-05-15T13:13:48.010Z","updated_at":"2026-05-15T13:13:51.470Z","avatar_url":"https://github.com/arkerone.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# smart-container\n\n  smart-container is a dependency injection container for NodeJS which can be configured with a configuration file.\n\n   [![npm version](https://badge.fury.io/js/smart-container.svg)](https://badge.fury.io/js/smart-container)\n   [![codebeat badge](https://codebeat.co/badges/a63e9383-f9a6-4e41-9e97-7557a9114fc6)](https://codebeat.co/projects/github-com-arkerone-smart-container-master)\n   [![Build Status](https://travis-ci.org/arkerone/smart-container.svg?branch=master)](https://travis-ci.org/arkerone/smart-container)\n   [![codecov](https://codecov.io/gh/arkerone/smart-container/branch/master/graph/badge.svg)](https://codecov.io/gh/arkerone/smart-container)\n\n\n\n## Installation\n```\n$ npm install --save smart-container\n```\n\n## Features\n\n  * Define classes or literal objects to container,\n  * Define properties to container,\n  * Inject dependencies in constructor,\n  * Inject dependencies in methods,\n  * Setting up the container with a configuration file,\n  * Lazy loading (The services are created when you need them).\n\n## Usage\n\n### Create and use the container without configuration file\n\n#### Get the container builder\n```js\nconst containerBuilder = require('smart-container');\n```\n\n#### Create the container\n```js\nconst container = containerBuilder.create();\n```\n\n#### Create and register a new service\n```js\n/* Create a service class */\nclass Hello {\n  constructor() {\n    this.msg = 'Hello world!';\n  }\n\n  sayHello() {\n    console.log(this.msg);\n  }\n}\n\n/* Register the service */\ncontainer.register('hello', Hello);\n```\n\n#### Get and use the service\n```js\ncontainer.get('hello').sayHello(); // Print 'Hello world!'\n```\n\n### The configuration file\nHere is a template of a service configuration file (the file can be a JSON or a JS file) :\n\n```js\nmodule.exports = {\n  properties: {\n    propertyName: 'property_value'\n  },\n  services: {\n    serviceName: {\n      path: 'relative_path_to_the_service',\n      constructorArgs: ['first_arg', 'second_arg' /*... others args*/],\n      isSingleton: false, /* By default a service is a singleton */\n      calls: [\n        {\n          method: 'method_name',\n          args: ['first_arg', 'second_arg' /*... others args*/]\n        }\n      ]\n    }\n  }\n};\n```\n#### The properties\n##### Define a property\nThe object `properties` is used to define a collection of properties. For each property, you must specify its name and its value :\n```js\n{\n  properties: {\n    firstName: 'John',\n    lastName: 'Doe'\n  }\n}\n```\nYou can create an object as property :\n```js\n{\n  properties: {\n    person: {\n      firstName: 'John',\n      lastName: 'Doe'\n    }\n  }\n}\n```\n##### process.env support\nIf you use a js configuration file instead of a JSON configuration file, you can use the environment variables:\n```js\n{\n  properties: {\n    host: process.env.DB_HOST,\n    username: process.env.DB_USER,\n    password: process.env.DB_PASS\n  }\n}\n```\n#### The services\n##### The name and path of the service\nThe object `services` is used to define a collection of services. For each service, you must specify its name and the path of its file :\n```js\n{\n  services: {\n    messagePrinter: {\n      path: './MessagePrinter'\n    }\n  }\n}\n```\n##### constructorArgs\nyou can specify the arguments of the service `constructor` :\n```js\n{\n  services: {\n    messagePrinter: {\n      path: './MessagePrinter',\n      constructorArgs: ['Hello world!']\n    }\n  }\n}\n```\nIt's possible to reference of a property (defined in the configuration file), just wrap the name of the property with `%` :\n```js\n{\n  services: {\n    messagePrinter: {\n      path: './MessagePrinter',\n      constructorArgs: ['%message%']\n    }\n  }\n}\n```\nIf the property is an object, you can access of the object property like that :\n```js\n'%person.firstName%'\n```\nIt's also possible to reference of a other service. Just prefix the service name with `@`:\n```js\n'@otherService'\n```\n##### isSingleton\nYou can specify if the service is a singleton or not (by default a service is a singleton) :\n```js\n{\n  services: {\n    messagePrinter: {\n      path: './MessagePrinter',\n      constructorArgs: ['%message%'],\n      isSingleton: false\n    }\n  }\n}\n```\nIn the case of a literal object, if `isSingleton` is set to false, the object Is copied. \n##### calls\nAt the creation of the service, it's possible to call several methods :\n```js\n{\n  services: {\n    messagePrinter: {\n      path: './MessagePrinter',\n      constructorArgs: ['%message%'],\n      calls: [{\n        method: 'setMessage',\n        args: ['Hello guys!']\n      }]\n    }\n  }\n}\n```\nYou can, like the arguments of the `constuctor`, make a reference to a property or a service.\n\n#### Build a container with the configuration file\n\n#####  Create a service class\nMessagePrinter.js\n```js\nmodule.exports = class MessagePrinter {\n  constructor(msg) {\n    this.msg = msg;\n  }\n\n  setMessage(msg) {\n    this.msg = msg;\n  }\n\n  print() {\n    console.log(this.msg);\n  }\n};\n```\n#####  Create the configuration file\nServices.js\n```js\nmodule.exports = {\n  properties: {\n    message: 'Hello world',\n  },\n  services: {\n    messagePrinter: {\n      path: './MessagePrinter',\n      constructorArgs: ['%message%'],\n      calls: [{\n        method: 'setMessage',\n        args: ['Hello guys!']\n      }]\n    }\n  }\n};\n```\n#####  Get the container builder\n```js\nconst containerBuilder = require('smart-container');\n```\n#####  Build the container\n```js\nconst container = containerBuilder.build(__dirname, './Services.js');\n```\n#### Get and use the service\n```js\ncontainer.get('messagePrinter').print(); // Print 'Hello guys!'\n```\n## API\n\n### ContainerBuilder\n\n#### create()\nCreate an empty container\n#### build(rootDir, configPath)\nCreate a container with a configuration file. The parameters are :\n* `rootDir`: The absolute path for the root directory (use `__dirname`),\n* `configPath`: The relative path of the configuration file.\n\n### Container\n\n#### load(rootDir, configPath)\nLoad a configuration file. The parameters are :\n* `rootDir`: The absolute path for the root directory (use `__dirname`),\n* `configPath`: The relative path of the configuration file.\n#### get(name)\nGet a service by its `name`\n#### register(name, serviceClass, isSingleton)\nRegister a service. The parameters are :\n * `name`: The name of the service,\n * `serviceClass`: the class or the literal object of the service,\n * `isSingleton`: (optional : by default true) true if the service is a singleton, false otherwise.\n \n This function return an `ServiceDefinition` object (see below).\n#### hasService(name)\nCheck if the service exists with its `name`\n#### getProperty(name)\nGet a property by its `name`. You can access of an object property like that :\n```js\n'person.firstName'\n```\n#### addProperty(name, value)\nAdd a property. The parameters are :\n * `name`: The name of the property,\n * `value`: the value of property.\n#### hasProperty(name)\nCheck if the property exists with its `name`.\n\n### ServiceDefinition\nThis object is used to describe a service.\n\n#### addArgument(value)\nAdd a argument `value` used by the constructor. You can use the symbol `@` to make reference to an other service or wrap the `value` with `%` to make reference to a property.\n#### addArguments(args)\nAdd several arguments used by the constructor. The parameter `args` is an array.\n#### addMethodCall(method, args)\nAdd a method call. The parameters are :\n * `method`:  the name of the method,\n * `args`: (optional) the array of method arguments.\n#### addMethodCalls(calls)\nAdd a several method calls. The parameter is :\n * `calls`:  the array of method calls.\n \nEach element of the `calls` array is an object with the following properties:\n* `method`: the name of the method,\n* `args`: the array of method arguments.\n\n## Examples\n\nCheck out the `examples` directory to see more complex examples.\n\n## License\nThe MIT License (MIT)\n\nCopyright (c) 2017 Axel SHAÏTA \u003cshaita.axel@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkerone%2Fsmart-container","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farkerone%2Fsmart-container","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkerone%2Fsmart-container/lists"}