@electron-tools/ioc
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -0,0 +0,0 @@ "use strict"; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +6,0 @@ exports.INSTANTIATION_SERVICE_ID = exports.register = exports.inject = exports.service = exports.default = void 0; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /*--------------------------------------------------------------------------------------------- |
export { default } from './instantiation'; | ||
export { service, inject, register, INSTANTIATION_SERVICE_ID } from './instantiation'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
@@ -0,0 +0,0 @@ export declare class Node<T> { |
export { default } from './instantiation'; | ||
export { service, inject, register, INSTANTIATION_SERVICE_ID } from './instantiation'; |
@@ -0,0 +0,0 @@ import 'reflect-metadata'; |
{ | ||
"name": "@electron-tools/ioc", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "DI implement of IOC", | ||
@@ -47,3 +47,3 @@ "main": "./dist/cjs/index.js", | ||
}, | ||
"readme": "# @electron-tools/ioc\n\n## Introduction\n\nA simple DI implement of IOC using typescript. inspired by vscode IOC implement.\n\n## Installation\n\n```bash\n# install by npm\n$npm install @electron-tools/ioc\n# install by pnpm\n$pnpm add @electron-tools/ioc\n# install by yarn\n$yarn add @electron-tools/ioc\n```\n\n## Usage\n\n1. enable `experimentalDecorators` option in your tsconfig.json.\n\n2. register your service by `service` decorator exported from this package.\n\n```ts\n// src/serviceA.ts\nimport { service } from '@electron-tools/ioc';\n\n@service('serviceA') // register ServiceA with unique id 'serviceA' using service decorator exported by this package.\nclass ServiceA {\n // ....\n}\n```\n\n3. use `inject` decorator inject your service to another service.\n\n```ts\n// src/serviceB.ts\nimport { service, inject } from '@electron-tools/ioc';\n\n@service('serviceB') // also register ServiceB with unique id 'serviceB'\nclass ServiceB {\n constructor(\n @inject('serviceA') // inject serviceA to serviceB, the only args passed to inject is the service unique id.\n readonly serviceA: ServiceA,\n ) {}\n}\n```\n\n4. import all your services and crate a IOC instance in your entry file.\n\n```ts\n// src/index.ts\nimport IOC from '@electron-tools/ioc';\nimport './serviceA.ts';\nimport './serviceB.ts';\n\nconst ioc = new IOC();\nconst serviceA = ioc.getService('serviceA');\nconst serviceB = ioc.getService('serviceB');\nconsole.log(serviceA instanceof ServiceA); // true\nconsole.log(serviceB instanceof ServiceB); // true\nconsole.log(serviceA === serviceB.a); // true\n```\n\n## Features\n\n1. Instance all service in one place. \n by default. service only be instanced when needed. in the case above. if you only call `ioc.getService('serviceA')`, serviceB will not be instance, cause serviceB is not dependencied by any service, but if you only call `ioc.getService('serviceB')`, serviceA will be instance, and inject into serviceB. this maybe not what you want. you can init all services in one place by call `ioc.init()`.\n\n```ts\nconst ioc = new IOC();\nioc.init(); // this statement will instance all services registered.\n```\n\n2. Cycle reference.\n if there are some cycle reference between your services. such as serviceA dependencied by serviceB, serviceB also dependencied by serviceA, you can resolve this issue by get service later instead of constructor of service.\n\n```ts\n// src/serviceA.ts\nimport IOC, { service, inject, INSTANTIATION_SERVICE_ID } from '@electron-tools/ioc';\n\n@service('serviceA') // register ServiceA with unique id 'serviceA' using service decorator exported by ioc.\nclass ServiceA {\n constructor(\n @inject(INSTANTIATION_SERVICE_ID) readonly ioc: IOC, // ioc itself is also a service can be injected.\n ) {}\n\n someMethod() {\n // dynamic get serviceB by ioc#getService API. then you can do anything what serviceB can do.\n const serviceB = this.ioc.getService('serviceB');\n serviceB.xxx;\n }\n}\n```\n" | ||
"readme": "# @electron-tools/ioc\r\n\r\n## Introduction\r\n\r\nA simple DI implement of IOC using typescript. inspired by vscode IOC implement.\r\n\r\n## Installation\r\n\r\n```bash\r\n# install by npm\r\n$npm install @electron-tools/ioc\r\n# install by pnpm\r\n$pnpm add @electron-tools/ioc\r\n# install by yarn\r\n$yarn add @electron-tools/ioc\r\n```\r\n\r\n## Usage\r\n\r\n1. enable `experimentalDecorators` option in your tsconfig.json.\r\n\r\n2. register your service by `service` decorator exported from this package.\r\n\r\n```ts\r\n// src/serviceA.ts\r\nimport { service } from '@electron-tools/ioc';\r\n\r\n@service('serviceA') // register ServiceA with unique id 'serviceA' using service decorator exported by this package.\r\nclass ServiceA {\r\n // ....\r\n}\r\n```\r\n\r\n3. use `inject` decorator inject your service to another service.\r\n\r\n```ts\r\n// src/serviceB.ts\r\nimport { service, inject } from '@electron-tools/ioc';\r\n\r\n@service('serviceB') // also register ServiceB with unique id 'serviceB'\r\nclass ServiceB {\r\n constructor(\r\n @inject('serviceA') // inject serviceA to serviceB, the only args passed to inject is the service unique id.\r\n readonly serviceA: ServiceA,\r\n ) {}\r\n}\r\n```\r\n\r\n4. import all your services and crate a IOC instance in your entry file.\r\n\r\n```ts\r\n// src/index.ts\r\nimport IOC from '@electron-tools/ioc';\r\nimport './serviceA.ts';\r\nimport './serviceB.ts';\r\n\r\nconst ioc = new IOC();\r\nconst serviceA = ioc.getService('serviceA');\r\nconst serviceB = ioc.getService('serviceB');\r\nconsole.log(serviceA instanceof ServiceA); // true\r\nconsole.log(serviceB instanceof ServiceB); // true\r\nconsole.log(serviceA === serviceB.a); // true\r\n```\r\n\r\n## Features\r\n\r\n1. Instance all service in one place. \r\n by default. service only be instanced when needed. in the case above. if you only call `ioc.getService('serviceA')`, serviceB will not be instance, cause serviceB is not dependencied by any service, but if you only call `ioc.getService('serviceB')`, serviceA will be instance, and inject into serviceB. this maybe not what you want. you can init all services in one place by call `ioc.init()`.\r\n\r\n```ts\r\nconst ioc = new IOC();\r\nioc.init(); // this statement will instance all services registered.\r\n```\r\n\r\n2. Cycle reference.\r\n if there are some cycle reference between your services. such as serviceA dependencied by serviceB, serviceB also dependencied by serviceA, you can resolve this issue by get service later instead of constructor of service.\r\n\r\n```ts\r\n// src/serviceA.ts\r\nimport IOC, { service, inject, INSTANTIATION_SERVICE_ID } from '@electron-tools/ioc';\r\n\r\n@service('serviceA') // register ServiceA with unique id 'serviceA' using service decorator exported by ioc.\r\nclass ServiceA {\r\n constructor(\r\n @inject(INSTANTIATION_SERVICE_ID) readonly ioc: IOC, // ioc itself is also a service can be injected.\r\n ) {}\r\n\r\n someMethod() {\r\n // dynamic get serviceB by ioc#getService API. then you can do anything what serviceB can do.\r\n const serviceB = this.ioc.getService('serviceB');\r\n serviceB.xxx;\r\n }\r\n}\r\n```\r\n" | ||
} |
@@ -0,0 +0,0 @@ # @electron-tools/ioc |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
42521
506
0