{"id":39036711,"url":"https://github.com/plopezm/tsinject","last_synced_at":"2026-01-17T17:44:43.066Z","repository":{"id":57137256,"uuid":"116500003","full_name":"plopezm/tsinject","owner":"plopezm","description":null,"archived":false,"fork":false,"pushed_at":"2018-03-10T20:35:17.000Z","size":49,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-05T06:41:33.398Z","etag":null,"topics":["cross-cutting-concerns","injection","interceptor","inversion-of-control","singleton-pattern","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/plopezm.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":"2018-01-06T16:59:01.000Z","updated_at":"2024-04-13T08:53:01.000Z","dependencies_parsed_at":"2022-09-01T03:00:57.708Z","dependency_job_id":null,"html_url":"https://github.com/plopezm/tsinject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/plopezm/tsinject","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Ftsinject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Ftsinject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Ftsinject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Ftsinject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plopezm","download_url":"https://codeload.github.com/plopezm/tsinject/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plopezm%2Ftsinject/sbom","scorecard":{"id":737993,"data":{"date":"2025-08-11","repo":{"name":"github.com/plopezm/tsinject","commit":"a5faa0ec3081e0d740f28f8b3cdf75a0879f6b10"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"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":"Code-Review","score":0,"reason":"Found 0/20 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":"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":"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":"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":"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":"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":"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":"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 11 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"}},{"name":"Vulnerabilities","score":0,"reason":"11 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T16:28:28.629Z","repository_id":57137256,"created_at":"2025-08-22T16:28:28.629Z","updated_at":"2025-08-22T16:28:28.629Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28513975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T13:38:16.342Z","status":"ssl_error","status_checked_at":"2026-01-17T13:37:44.060Z","response_time":85,"last_error":"SSL_read: 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":["cross-cutting-concerns","injection","interceptor","inversion-of-control","singleton-pattern","typescript"],"created_at":"2026-01-17T17:44:42.360Z","updated_at":"2026-01-17T17:44:43.057Z","avatar_url":"https://github.com/plopezm.png","language":"TypeScript","readme":"# tsinject\n\nDependency injection \u0026 cross-cutting concern library. This library provides the necessary tools to implement any application using DI and interceptors.\n\n# Installing\n\n```\nnpm install --save @plopezm/tsinject\n```\n\n# How to use it\n\n1. Defining a simple class: \n\n```typescript\n@Injectable\nexport class UserService {\n\n    users: any = {};\n\n    constructor(){\n        this.users[\"plopez\"] = {\n            username: \"plopez\",\n            password: \"testing\"\n        }\n    }\n\n    get(username: string): any{\n        return this.users[username];\n    }\n\n    create(user: User): any{\n        this.users[user.username] = user;\n        return user;\n    }\n\n}\n\n```\n\n2. Use your singleton\n\n```typescript\nimport { UserService } from './services/user.service';\nimport { Inject } from '@plopezm/tsinject';\n\nexport class UserResource {\n\n    @Inject()\n    userService: UserService;\n\n    constructor(){        \n    }\n\n}\n```\n\n# Using an implementation gotten from a factory\n\nInjecting from a factory is really easy. In this case we don't have to register any class in the InjectionFactory. This is due to @Produces(\"\") decorator registers a new singleton using the name included. To use this factory object we have to use @Inject(\"\") with the same name that you used in @Produces(\"\").\n\n```typescript\nimport { Inject, Produces } from \"@plopezm/tsinject\";\n\nexport class UserResource {\n\n    // It gets the default singleton registered\n    @Inject()\n    userService: UserService;\n\n    // It gets the specific singleton created in the named produces method\n    @Inject(\"MyFactoryService\")\n    userServiceFromFactory: UserService;\n\n    ...\n}\n\nexport class UserServiceFactory {\n    // Creates a new object and registers it in the InjectionFactory automatically using the name included in @Produces\n    @Produces(\"MyFactoryService\")\n    static produceUserService() {\n        var userService = new UserService();\n        userService.initialize(example, example2);\n        return userService;\n    }\n}\n\n```\n\n# Implementing Interceptors\n\nInterceptors is the way that we use to implement cross-cutting functionalities. This library provides a way to implement our interceptors for a typescript nodejs application. This library supports multi-interceptor declaration, so you can declare multiple interceptors for a method.\n\n1. Implementing interceptors\n\n```typescript\n    import { Interceptor, Intercepted, InterceptorComponent, NextInterceptor, InterceptedClass } from \"@plopezm/tsinject\";\n\n    @Interceptor\n    class ExampleInterceptor implements InterceptorComponent{\n        invoke(next: NextInterceptor, classIntercepted: InterceptedClass, ...args: any[]): any {\n\n            // Here the real method (or next interceptor) is executed\n            // We have to get the result returned by next function.\n            // next() could be a call to the real method or a call to the next interceptor\n            let result = next(...args);\n\n            // Finally we have to return the value that we want to return ( we can modify it, or args, ...)\n            // In this example we are going to modify the original method output adding '[]'\n            return `[${result}]`;\n        }\n    }\n```\n\n2. Declaring the interceptor in the desired method\n\n```typescript\n    @Intercepted(ExampleInterceptor)\n    getNamedHelloString(name: string): string {\n        return `Hello Mr ${name}`;\n    }\n```\n\n3. Executing our method\n\n```typescript\n    let obj = new ExampleIntercepted();\n    // The output will be '[Hello Mr Pablo]' instead of 'Hello Mr Pablo'\n    const result = obj.getNamedHelloString('Pablo');\n```\n\nIn addition is it possible to set more than one interceptors for a method. The order of declaration is important because it will detemine the execution order. For example:\n\n```typescript\n    @Intercepted(ExampleInterceptor, ExampleInterceptor2)\n    getNamedHelloWithSurnameString2(name: string, surname: string, surname2: string): string {\n        return `Hello Mr ${name} ${surname} ${surname2}`;\n    }\n```\n\nIn this example the interceptor 'ExampleInterceptor' will execute in first place, then 'ExampleInterceptor2' and finally the method 'getNamedHelloWithSurnameString2'\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplopezm%2Ftsinject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplopezm%2Ftsinject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplopezm%2Ftsinject/lists"}