{"id":22540114,"url":"https://github.com/zhouhoujun/tsioc","last_synced_at":"2025-08-22T05:32:45.002Z","repository":{"id":37431427,"uuid":"110641277","full_name":"zhouhoujun/tsioc","owner":"zhouhoujun","description":"AOP,  Ioc container, Boot framework, unit testing framework , activities workflow framework.","archived":false,"fork":false,"pushed_at":"2024-11-28T10:17:14.000Z","size":17699,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-01T05:04:29.973Z","etag":null,"topics":["activities","activity","aop","boot","bootstrap","build-tool","decorators","framework","ioc","ioc-container","pack","type","type-ioc","typescript","typescript-decorators","unit","unit-test","unittest","workflow"],"latest_commit_sha":null,"homepage":"","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/zhouhoujun.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-14T04:39:38.000Z","updated_at":"2024-07-19T08:10:58.000Z","dependencies_parsed_at":"2022-07-14T04:50:30.796Z","dependency_job_id":"5833c8fc-e5a6-404e-abdf-6d7d094bcdba","html_url":"https://github.com/zhouhoujun/tsioc","commit_stats":{"total_commits":2325,"total_committers":2,"mean_commits":1162.5,"dds":0.3234408602150538,"last_synced_commit":"f996a617fde98955a9cf6209752495447662f4ce"},"previous_names":[],"tags_count":200,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhouhoujun%2Ftsioc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhouhoujun%2Ftsioc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhouhoujun%2Ftsioc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhouhoujun%2Ftsioc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhouhoujun","download_url":"https://codeload.github.com/zhouhoujun/tsioc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230561014,"owners_count":18245324,"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":["activities","activity","aop","boot","bootstrap","build-tool","decorators","framework","ioc","ioc-container","pack","type","type-ioc","typescript","typescript-decorators","unit","unit-test","unittest","workflow"],"created_at":"2024-12-07T12:09:46.514Z","updated_at":"2024-12-20T09:07:43.357Z","avatar_url":"https://github.com/zhouhoujun.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# packaged @tsdi/ioc\n\nThis repo is for distribution on `npm`. The source for this module is in the\n[main repo](https://github.com/zhouhoujun/tsioc).\n\n`@tsdi/ioc` is Ioc container, Injector, via typescript decorator.\n\nversion 5+ of [`@ts-ioc/core`](https://www.npmjs.com/package/@ts-ioc/core) [`tsioc`](https://www.npmjs.com/package/tsioc)\n\n# builder\n\n```shell\nbuild: npm run build\n\n//build with version:\nnpm run build -- --setvs=4.0.0-beta\n\n//deploy: \n./deploy.cmd\n//or\n npm run build -- --deploy=true\n\n```\n\n# Install\n\n```shell\n\nnpm install @tsdi/ioc\n\n```\n\n## add extends modules\n\n### use aop\n\n```shell\n\n// install aop\nnpm install @tsdi/aop\n\n```\n\n```ts\n\nimport { AopModule } from '@tsdi/aop';\nimport { IocContainer } from '@tsdi/ioc';\n\nlet container = new IocContainer();\n\n// use aop.\ncontainer.use(AopModule);\n// also can\ncontainer.register(AopModule);\n// or\ncontainer.inject(AopModule)\n//or\ncontainer.injectModule(AopModule)\n\n```\n\n### use aop logs\n\n```shell\n// install aop logs\nnpm install @tsdi/logs\n```\n\n```ts\n\nimport { LogModule } from '@tsdi/logs';\n// in server\nimport { ContainerBuilder } from '@tsdi/platform-server'\n// in browser\nimport { ContainerBuilder } from '@tsdi/platform-browser'\n\nlet builder = new ContainerBuilder();\n\nlet container = build.create();\n\ncontainer.use(LogModule);\n\n```\n\n# Documentation\n\n## core\n\n### extends ioc\n1. `@IocExt` class decortator, use to define the class is Ioc extends module. it will auto run after registered to helper your to setup module.\n2. add service resolve.\n3. module inject.\n\n\n## Ioc\n\n1. Register one class will auto register depdence class (must has a class decorator).\n\n2. get Instance can auto create constructor param.  (must has a class decorator or register in container).\n\n### decorators\n\n1. `@Abstract`  abstract class decorator.\n2. `@AutoRun`   class, method decorator, use to define the class auto run (via a method or not) after registered.\n3. `@AutoWried`  property or param decorator, use to auto wried type instance or value to the instance of one class with the decorator.\n4. `@Inject`  property or param decorator, use to auto wried type instance or value to the instance of one class with the decorator.\n5. `@Injectable` class decortator, use to define the class. it can setting provider to some token, singleton or not.\n6. `@AutoWried` method decorator.\n7. `@Param`   param decorator, use to auto wried type instance or value to the instance of one class with the decorator.\n8. `@Singleton` class decortator, use to define the class is singleton.\n9. `@Providers` Providers decorator, for class. use to add private ref service for the class.\n10. `@Refs` Refs decorator, for class. use to define the class as a service for target.\n\n\n## AOP\n\nIt's a dynamic aop base on ioc.\n\ndefine a Aspect class, must with decorator:\n\n* `@Aspect` Aspect decorator, define for class.  use to define class as aspect. it can setting provider to some token, singleton or not.\n\n* `@Before(matchstring|RegExp)` method decorator,  aop Before advice decorator.\n\n* `@After(matchstring|RegExp)`  method decorator,  aop after advice decorator.\n\n* `@Around(matchstring|RegExp)`  method decorator,  aop around advice decorator.\n\n* `@AfterThrowing(matchstring|RegExp)`  method decorator,  aop AfterThrowing advice decorator.\n\n* `@AfterReturning(matchstring|RegExp)`  method decorator,  aop AfterReturning advice decorator.\n\n* `@Pointcut(matchstring|RegExp)`  method decorator,  aop Pointcut advice decorator.\n\n\nsee [simples](https://github.com/zhouhoujun/tsioc/tree/master/packages/aop/test/aop)\n\n\n## boot\nDI Module manager, application bootstrap. base on AOP.\n\n*  `@DIModule` DIModule decorator, use to define class as DI Module.\n*  `@Bootstrap` Bootstrap decorator, use to define class as bootstrp module.\n*  `@Annotation` Annotation decorator, use to define class build metadata config.\n*  `@Message`  Message decorator, for class. use to define the class as message handle register in global message queue.\n\n[mvc boot simple](https://github.com/zhouhoujun/type-mvc/tree/master/packages/simples)\n\n```ts\n\nimport { DIModule, BootApplication } from '@tsdi/boot';\n\n\nexport class TestService {\n    testFiled = 'test';\n    test() {\n        console.log('test');\n    }\n}\n\n@DIModule({\n    providers: [\n        { provide: 'mark', useFactory: () =\u003e 'marked' },\n        TestService\n    ],\n    exports: [\n\n    ]\n})\nexport class ModuleA {\n\n}\n\n@Injectable\nexport class ClassSevice {\n    @Inject('mark')\n    mark: string;\n    state: string;\n    start() {\n        console.log(this.mark);\n    }\n}\n\n@Aspect\nexport class Logger {\n\n    @Around('execution(*.start)')\n    log() {\n        console.log('start........');\n    }\n}\n\n\n@DIModule({\n    imports: [\n        AopModule,\n        ModuleA\n    ],\n    providers:[\n        Logger,\n        ClassSevice\n    ]\n    bootstrap: ClassSevice\n})\nexport class ModuleB {\n\n}\n\nBootApplication.run(ModuleB);\n\n```\n\n## components\n*  `@Component`  Component decorator,  use to defaine class as component with template.\n*  `@Input` Input decorator, use to define property or param as component binding field or args.\n\nsee [ activity build boot simple](https://github.com/zhouhoujun/tsioc/blob/master/packages/activities/taskfile.ts)\n\n\n## [Activites](https://github.com/zhouhoujun/tsioc/tree/master/packages/activities)\n\n* [activities](https://github.com/zhouhoujun/tsioc/tree/master/packages/activities)\n* [pack](https://github.com/zhouhoujun/tsioc/tree/master/packages/pack)\n\n### create Container\n\n```ts\n\nlet container = new IocContainer();\n\n```\n\n###  Container is ioc root.\n\nsee @tsdi/ioc interface [IIocContainer](https://github.com/zhouhoujun/tsioc/blob/master/packages/ioc/src/IIocContainer.ts)\n\nsee @tsdi/core interface [IContainer](https://github.com/zhouhoujun/tsioc/blob/master/packages/core/src/IContainer.ts)\n\n```ts\n\n// 1. register a class\ncontainer.register(Person);\n\n// 2. register a factory;\ncontainer.register(Person, (container)=\u003e {\n    ...\n    return new Person(...);\n});\n\n// 3. register with keyword\ncontainer.register('keyword', Perosn);\n\n// 4. register with alais\ncontainer.register(new Registration(Person, aliasname));\n\n// register singleton\ncontainer.registerSingleton(Person)\n\n// bind provider\ncontainer.bindProvider\n// bind providers.\ncontainer.bindProviders\n\n```\n\n### Injector is basic ioc injector.\n\nsee interface [IInjector](https://github.com/zhouhoujun/tsioc/blob/master/packages/ioc/src/IInjector.ts)\n\n```ts\n\n// get the injector of Person class type injected.\nlet injector =  container.getInjector(Person);\n\n// create new injector\nlet injector = container.createInjector();\n// or create new injector via\nlet injector = container.getInstance(InjectorFactoryToken);\n```\n\n### Invoke method\n\nyou can use yourself `MethodAccessor` by implement IMethodAccessor, register `MethodAccessorToken` with your `MethodAccessor` in container,   see [interface](https://github.com/zhouhoujun/tsioc/blob/master/packages/ioc/src/IIocContainer.ts).\n\n```ts\n\n@Injectable\nclass Person {\n    constructor() {\n\n    }\n    say() {\n        return 'I love you.'\n    }\n}\n\n@Injectable\nclass Child extends Person {\n    constructor() {\n        super();\n    }\n    say() {\n        return 'Mama';\n    }\n}\n\nclass MethodTest {\n    constructor() {\n\n    }\n\n    @AutoWried\n    sayHello(person: Person) {\n        return person.say();\n    }\n}\n\nclass MethodTest2 {\n    constructor() {\n\n    }\n\n    @AutoWried()\n    sayHello( @Inject(Child) person: Person) {\n        return person.say();\n    }\n}\n\nclass MethodTest3 {\n    constructor() {\n\n    }\n\n    @AutoWried\n    sayHello( @Inject(Child) personA: Person, personB: Person) {\n        return personA.say() + ', '  + personB.say();\n    }\n}\n\n@Injectable\nclass Geet {\n    constructor(private name: string){\n\n    }\n\n    print(hi?:string){\n        return `${hi}, from ${this.name}`;\n    }\n}\n\ncontainer.register(Geet);\n\ncontainer.invoke(Geet, gt=\u003e gt.print, ... //inject providers.)\n\nlet instance = container.resolve(Geet, )\n\ncontainer.invoke(instance, gt=\u003e gt.print, ...//inject providers.);\ncontainer.invoke(instance, 'print', ...);\n\ncontainer.register(MethodTest);\ncontainer.invoke(MethodTest, 'sayHello');\n\ncontainer.register(MethodTest2);\ncontainer.invoke(MethodTest2, tg=\u003e tg.sayHello);\n\ncontainer.register(MethodTest3);\ncontainer.invoke(MethodTest3, 'sayHello');\n\n\n```\n\n\n## Use Demo\n\n```ts\n\nimport { Method, ContainerBuilder, AutoWired, Injectable, Singleton, IContainer, ParameterMetadata, Param, Aspect } from '@tsdi/core';\n\n\nexport class SimppleAutoWried {\n    constructor() {\n    }\n\n    @AutoWired\n    dateProperty: Date;\n}\n\n@Singleton\nexport class Person {\n    name = 'testor';\n}\n// \u003e v0.3.5 all class decorator can depdence.\n@Singleton\n// @Injectable\nexport class RoomService {\n    constructor() {\n\n    }\n    @AutoWired\n    current: Date;\n}\n\n@Injectable()\nexport class ClassRoom {\n    constructor(public service: RoomService) {\n\n    }\n}\n\nexport abstract class Student {\n    constructor() {\n    }\n    abstract sayHi(): string;\n}\n\n@Injectable({ provide: Student })\nexport class MiddleSchoolStudent extends Student {\n    constructor() {\n        super();\n    }\n    sayHi() {\n        return 'I am a middle school student';\n    }\n}\n\n@Injectable()\nexport class MClassRoom {\n    @AutoWired(MiddleSchoolStudent)\n    leader: Student;\n    constructor() {\n\n    }\n}\n\n\n@Injectable({ provide: Student, alias: 'college' })\nexport class CollegeStudent extends Student {\n    constructor() {\n        super();\n    }\n    sayHi() {\n        return 'I am a college student';\n    }\n}\n\n@Injectable\nexport class CollegeClassRoom {\n    constructor(\n        @Param(CollegeStudent)\n        @AutoWired(CollegeStudent)\n        public leader: Student) {\n\n    }\n}\n\n\n@Injectable\nexport class InjMClassRoom {\n    // @Inject(MiddleSchoolStudent)\n    @Inject\n    // @Inject({ type: MiddleSchoolStudent })\n    // @Inject({ provider: MiddleSchoolStudent })\n    leader: Student;\n    constructor() {\n\n    }\n}\n\n\nexport interface IClassRoom {\n    leader: Student;\n}\n\n@Injectable\nexport class InjCollegeClassRoom {\n    constructor(\n        // all below decorator can work, also @AutoWired, @Param is.\n        // @Inject(new Registration(Student, 'college')) // need CollegeStudent also register.\n        @Inject(CollegeStudent)\n        // @Inject({ provider: CollegeStudent })\n        // @Inject({ provider: Student, alias: 'college' }) //need CollegeStudent also register.\n        // @Inject({ type: CollegeStudent })\n        public leader: Student\n    ) {\n\n    }\n}\n\n@Injectable\nexport class InjCollegeAliasClassRoom {\n    constructor(\n        // all below decorator can work, also @AutoWired, @Param is.\n        @Inject(new Registration(Student, 'college')) // need CollegeStudent also register.\n        // @Inject(CollegeStudent)\n        // @Inject({ provider: CollegeStudent })\n        // @Inject({ provider: Student, alias: 'college' }) // need CollegeStudent also register.\n        // @Inject({ type: CollegeStudent })\n        public leader: Student\n    ) {\n\n    }\n}\n\n\n@Injectable('StringClassRoom')\nexport class StingMClassRoom {\n    // @Inject(MiddleSchoolStudent)\n    @Inject\n    // @Inject({ type: MiddleSchoolStudent })\n    leader: Student;\n    constructor() {\n\n    }\n}\n\nexport class StringIdTest {\n    constructor(@Inject('StringClassRoom') public room: IClassRoom) {\n\n    }\n}\n\nexport const CollClassRoom = Symbol('CollegeClassRoom');\n\n@Injectable(CollClassRoom)\nexport class SymbolCollegeClassRoom {\n\n    @Inject(CollegeStudent)\n    leader: Student;\n    constructor() {\n\n    }\n}\n\nexport class SymbolIdest {\n    @Inject(CollClassRoom)\n    public room: IClassRoom\n    constructor() {\n\n    }\n}\n\n@Injectable\nclass MethodTestPerson {\n    say() {\n        return 'hello word.'\n    }\n}\n\nclass MethodTest {\n\n    @AutoWried\n    sayHello(person: MethodTestPerson) {\n        return person.say();\n    }\n}\n\n\n// 1. Custom register one class will auto inject depdence class (must has a class decorator).\n\nlet builder = new ContainerBuilder();\nlet container = builder.create();\n\n\ncontainer.register(MethodTest);\ncontainer.invoke(MethodTest, 'sayHello')\n    .then(data =\u003e{\n        console.log(data);\n    });\n\ncontainer.register(SimppleAutoWried);\nlet instance = container.get(SimppleAutoWried);\nconsole.log(instance.dateProperty);\n\n\ncontainer.register(ClassRoom);\nlet room = container.get(ClassRoom);\nconsole.log(room.service.current);\n\ncontainer.register(MiddleSchoolStudent);\ncontainer.register(CollegeStudent);\n\nlet student = container.get(Student);\nconsole.log(student.sayHi());\n\nlet student2 = container.get(new Registration(Student, 'college'));\n\nconsole.log(student2.sayHi());\n\nlet student3 = container.get(Student, 'college'));\n\nconsole.log(student3.sayHi());\n\n\nbuilder.build({\n    files: __dirname + '/*{.ts,.js}'\n})\n    .then(container =\u003e {\n        let instance = container.get(Student);\n        console.log(instance.sayHi());\n\n        let instance2 = container.get(new Registration(Student, 'college'));\n        console.log(instance2.sayHi());\n\n        let instance3 = container.get(Student, 'college');\n        console.log(instance3.sayHi())\n    });\n\n\n\n```\n\n## Extend decorator, Demo fo extends \n\nsee AOP extends (https://github.com/zhouhoujun/tsioc/blob/master/packages/aop/src/AopModule.ts)\nYou can extend yourself decorator via:\n\n## Documentation\nDocumentation is available on the\n* [@tsdi/ioc document](https://github.com/zhouhoujun/tsioc/tree/master/packages/ioc).\n* [@tsdi/aop document](https://github.com/zhouhoujun/tsioc/tree/master/packages/aop).\n* [@tsdi/core document](https://github.com/zhouhoujun/tsioc/tree/master/packages/core).\n* [@tsdi/boot document](https://github.com/zhouhoujun/tsioc/tree/master/packages/boot).\n* [@tsdi/components document](https://github.com/zhouhoujun/tsioc/tree/master/packages/components).\n* [@tsdi/activities document](https://github.com/zhouhoujun/tsioc/tree/master/packages/activities).\n* [@tsdi/typeorm-adapter document](https://github.com/zhouhoujun/tsioc/tree/master/packages/typeorm-adapter).\n* [@tsdi/unit document](https://github.com/zhouhoujun/tsioc/tree/master/packages/unit).\n* [@tsdi/unit-console document](https://github.com/zhouhoujun/tsioc/tree/master/packages/unit-console).\n* [@tsdi/cli document](https://github.com/zhouhoujun/tsioc/tree/master/packages/cli).\n\n## License\n\nMIT © [Houjun](https://github.com/zhouhoujun/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhouhoujun%2Ftsioc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhouhoujun%2Ftsioc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhouhoujun%2Ftsioc/lists"}