Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tsed/di

Package Overview
Dependencies
Maintainers
5
Versions
1007
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsed/di - npm Package Compare versions

Comparing version 4.34.3 to 5.0.0

1

lib/interfaces/index.d.ts

@@ -5,3 +5,2 @@ export * from "./IInjectableMethod";

export * from "./OnInit";
export * from "./OnInjectorReady";
export * from "./OnDestroy";

@@ -8,0 +7,0 @@ export * from "./ProviderScope";

import { RegistryKey, Type } from "@tsed/core";
import { Provider } from "../class/Provider";
import { IInjectableMethod, IProvider, ProviderScope } from "../interfaces";
import { IInjectableMethod, ProviderScope } from "../interfaces";
import { ProviderType } from "../interfaces/ProviderType";

@@ -206,204 +206,2 @@ export interface IDISettings {

private static checkPromiseStatus;
/**
* Invoke the class and inject all services that required by the class constructor.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const myService = injectorService.invoke<MyService>(MyService);
* }
* }
* ```
*
* @param target The injectable class to invoke. Class parameters are injected according constructor signature.
* @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
* @param designParamTypes Optional object. List of injectable types.
* @param requiredScope
* @returns {T} The class constructed.
*/
static invoke<T>(target: any, locals?: Map<string | Function, any>, designParamTypes?: any[], requiredScope?: boolean): T;
/**
* Construct the service with his dependencies.
* @param target The service to be built.
* @deprecated
*/
static construct<T>(target: Type<any> | symbol): T;
/**
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
* @param eventName The event name to emit at all services.
* @param args List of the parameters to give to each services.
* @returns {Promise<any[]>} A list of promises.
*/
static emit(eventName: string, ...args: any[]): Promise<any>;
/**
* Get a service or factory already constructed from his symbol or class.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const myService = injectorService.get<MyService>(MyService);
* }
* }
* ```
*
* @param target The class or symbol registered in InjectorService.
* @returns {boolean}
*/
static get<T>(target: RegistryKey): T;
/**
* Invoke a class method and inject service.
*
* #### IInjectableMethod options
*
* * **target**: Optional. The class instance.
* * **methodName**: `string` Optional. The method name.
* * **designParamTypes**: `any[]` Optional. List of injectable types.
* * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* class MyService {
* constructor(injectorService: InjectorService) {
* injectorService.invokeMethod(this.method.bind(this), {
* target: this,
* methodName: 'method'
* });
* }
*
* method(otherService: OtherService) {}
* }
* ```
*
* @returns {any}
* @param handler The injectable method to invoke. Method parameters are injected according method signature.
* @param options Object to configure the invocation.
*/
static invokeMethod(handler: any, options: IInjectableMethod<any> | any[]): any;
/**
* Set a new provider from providerSetting.
* @param provider provide token.
* @param instance Instance
* @deprecated Use registerProvider or registerService or registerFactory instead of
*/
static set(provider: IProvider<any> | any, instance?: any): typeof InjectorService;
/**
* Check if the service of factory exists in `InjectorService`.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const exists = injectorService.has(MyService); // true or false
* }
* }
* ```
*
* @param target The service class
* @returns {boolean}
*/
static has(target: any): boolean;
/**
* Initialize injectorService and load all services/factories.
*/
static load(): Promise<any>;
/**
* Add a new service in the registry. This service will be constructed when `InjectorService`will loaded.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export default class MyFooService {
* constructor(){}
* getFoo() {
* return "test";
* }
* }
*
* InjectorService.service(MyFooService);
* const injector = new InjectorService();
* injector.load();
*
* const myFooService = injector.get<MyFooService>(MyFooService);
* myFooService.getFoo(); // test
* ```
*
* @param target The class to add in registry.
* @deprecated Use registerService or registerFactory instead of.
*/
static service(target: any): void;
/**
* Add a new factory in `InjectorService` registry.
*
* #### Example with symbol definition
*
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export interface IMyFooFactory {
* getFoo(): string;
* }
*
* export type MyFooFactory = IMyFooFactory;
* export const MyFooFactory = Symbol("MyFooFactory");
*
* InjectorService.factory(MyFooFactory, {
* getFoo: () => "test"
* });
*
* @Service()
* export class OtherService {
* constructor(@Inject(MyFooFactory) myFooFactory: MyFooFactory){
* console.log(myFooFactory.getFoo()); /// "test"
* }
* }
* ```
*
* > Note: When you use the factory method with Symbol definition, you must use the `@Inject()`
* decorator to retrieve your factory in another Service. Advice: By convention all factory class name will be prefixed by
* `Factory`.
*
* #### Example with class
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export class MyFooService {
* constructor(){}
* getFoo() {
* return "test";
* }
* }
*
* InjectorService.factory(MyFooService, new MyFooService());
*
* @Service()
* export class OtherService {
* constructor(myFooService: MyFooService){
* console.log(myFooFactory.getFoo()); /// "test"
* }
* }
* ```
* @deprecated Use registerFactory instead of
*/
static factory(target: any, instance: any): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
var _a, _b, _c;
const core_1 = require("@tsed/core");

@@ -11,3 +10,2 @@ const ts_log_debug_1 = require("ts-log-debug");

const ProviderRegistry_1 = require("../registries/ProviderRegistry");
let globalInjector;
/**

@@ -41,3 +39,2 @@ * This service contain all services collected by `@Service` or services declared manually with `InjectorService.factory()` or `InjectorService.service()`.

this._scopes = {};
globalInjector = this;
this.initInjector();

@@ -409,6 +406,2 @@ }

if (service && eventName in service) {
/* istanbul ignore next */
if (eventName === "$onInjectorReady") {
ts_log_debug_1.$log.warn("$onInjectorReady hook is deprecated, use $onInit hook insteadof. See https://goo.gl/KhvkVy");
}
const promise = service[eventName](...args);

@@ -446,312 +439,3 @@ /* istanbul ignore next */

}
/**
* Invoke the class and inject all services that required by the class constructor.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const myService = injectorService.invoke<MyService>(MyService);
* }
* }
* ```
*
* @param target The injectable class to invoke. Class parameters are injected according constructor signature.
* @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
* @param designParamTypes Optional object. List of injectable types.
* @param requiredScope
* @returns {T} The class constructed.
*/
/* istanbul ignore next */
static invoke(target, locals = new Map(), designParamTypes, requiredScope = false) {
return globalInjector.invoke(target, locals, designParamTypes, requiredScope);
}
/**
* Construct the service with his dependencies.
* @param target The service to be built.
* @deprecated
*/
/* istanbul ignore next */
static construct(target) {
const provider = ProviderRegistry_1.ProviderRegistry.get(target);
return this.invoke(provider.useClass);
}
/**
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
* @param eventName The event name to emit at all services.
* @param args List of the parameters to give to each services.
* @returns {Promise<any[]>} A list of promises.
*/
/* istanbul ignore next */
static emit(eventName, ...args) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
return globalInjector.emit(eventName, args);
});
}
/**
* Get a service or factory already constructed from his symbol or class.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const myService = injectorService.get<MyService>(MyService);
* }
* }
* ```
*
* @param target The class or symbol registered in InjectorService.
* @returns {boolean}
*/
/* istanbul ignore next */
static get(target) {
return globalInjector.get(target).instance;
}
/**
* Invoke a class method and inject service.
*
* #### IInjectableMethod options
*
* * **target**: Optional. The class instance.
* * **methodName**: `string` Optional. The method name.
* * **designParamTypes**: `any[]` Optional. List of injectable types.
* * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* class MyService {
* constructor(injectorService: InjectorService) {
* injectorService.invokeMethod(this.method.bind(this), {
* target: this,
* methodName: 'method'
* });
* }
*
* method(otherService: OtherService) {}
* }
* ```
*
* @returns {any}
* @param handler The injectable method to invoke. Method parameters are injected according method signature.
* @param options Object to configure the invocation.
*/
/* istanbul ignore next */
static invokeMethod(handler, options) {
return globalInjector.invokeMethod(handler, options);
}
/**
* Set a new provider from providerSetting.
* @param provider provide token.
* @param instance Instance
* @deprecated Use registerProvider or registerService or registerFactory instead of
*/
/* istanbul ignore next */
static set(provider, instance) {
if (!provider.provide) {
provider = {
provide: provider,
type: "factory",
useClass: provider,
instance: instance || provider
};
}
ProviderRegistry_1.registerProvider(provider);
return InjectorService;
}
/**
* Check if the service of factory exists in `InjectorService`.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const exists = injectorService.has(MyService); // true or false
* }
* }
* ```
*
* @param target The service class
* @returns {boolean}
*/
/* istanbul ignore next */
static has(target) {
return globalInjector.has(target);
}
/**
* Initialize injectorService and load all services/factories.
*/
/* istanbul ignore next */
static load() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!globalInjector) {
globalInjector = new InjectorService();
}
return globalInjector.load();
});
}
/**
* Add a new service in the registry. This service will be constructed when `InjectorService`will loaded.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export default class MyFooService {
* constructor(){}
* getFoo() {
* return "test";
* }
* }
*
* InjectorService.service(MyFooService);
* const injector = new InjectorService();
* injector.load();
*
* const myFooService = injector.get<MyFooService>(MyFooService);
* myFooService.getFoo(); // test
* ```
*
* @param target The class to add in registry.
* @deprecated Use registerService or registerFactory instead of.
*/
/* istanbul ignore next */
static service(target) {
return ProviderRegistry_1.registerService(target);
}
/**
* Add a new factory in `InjectorService` registry.
*
* #### Example with symbol definition
*
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export interface IMyFooFactory {
* getFoo(): string;
* }
*
* export type MyFooFactory = IMyFooFactory;
* export const MyFooFactory = Symbol("MyFooFactory");
*
* InjectorService.factory(MyFooFactory, {
* getFoo: () => "test"
* });
*
* @Service()
* export class OtherService {
* constructor(@Inject(MyFooFactory) myFooFactory: MyFooFactory){
* console.log(myFooFactory.getFoo()); /// "test"
* }
* }
* ```
*
* > Note: When you use the factory method with Symbol definition, you must use the `@Inject()`
* decorator to retrieve your factory in another Service. Advice: By convention all factory class name will be prefixed by
* `Factory`.
*
* #### Example with class
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export class MyFooService {
* constructor(){}
* getFoo() {
* return "test";
* }
* }
*
* InjectorService.factory(MyFooService, new MyFooService());
*
* @Service()
* export class OtherService {
* constructor(myFooService: MyFooService){
* console.log(myFooFactory.getFoo()); /// "test"
* }
* }
* ```
* @deprecated Use registerFactory instead of
*/
/* istanbul ignore next */
static factory(target, instance) {
return ProviderRegistry_1.registerFactory(target, instance);
}
}
tslib_1.__decorate([
core_1.Deprecated("removed feature"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object, Map, Array, Boolean]),
tslib_1.__metadata("design:returntype", typeof (_a = typeof T !== "undefined" && T) === "function" ? _a : Object)
], InjectorService, "invoke", null);
tslib_1.__decorate([
core_1.Deprecated("removed feature"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", typeof (_b = typeof T !== "undefined" && T) === "function" ? _b : Object)
], InjectorService, "construct", null);
tslib_1.__decorate([
core_1.Deprecated("removed feature"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [String, Object]),
tslib_1.__metadata("design:returntype", Promise)
], InjectorService, "emit", null);
tslib_1.__decorate([
core_1.Deprecated("removed feature"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", typeof (_c = typeof T !== "undefined" && T) === "function" ? _c : Object)
], InjectorService, "get", null);
tslib_1.__decorate([
core_1.Deprecated("removed feature"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object, Object]),
tslib_1.__metadata("design:returntype", void 0)
], InjectorService, "invokeMethod", null);
tslib_1.__decorate([
core_1.Deprecated("Use registerService(), registerFactory() or registerProvider() util instead of"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object, Object]),
tslib_1.__metadata("design:returntype", void 0)
], InjectorService, "set", null);
tslib_1.__decorate([
core_1.Deprecated("static InjectorService.has(). Removed feature."),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", Boolean)
], InjectorService, "has", null);
tslib_1.__decorate([
core_1.Deprecated("removed feature"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", []),
tslib_1.__metadata("design:returntype", Promise)
], InjectorService, "load", null);
tslib_1.__decorate([
core_1.Deprecated("Use registerService() util instead of"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object]),
tslib_1.__metadata("design:returntype", void 0)
], InjectorService, "service", null);
tslib_1.__decorate([
core_1.Deprecated("Use registerFactory() util instead of"),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [Object, Object]),
tslib_1.__metadata("design:returntype", void 0)
], InjectorService, "factory", null);
exports.InjectorService = InjectorService;

@@ -758,0 +442,0 @@ /**

6

package.json
{
"name": "@tsed/di",
"version": "4.34.3",
"version": "5.0.0",
"description": "DI module for Ts.ED Framework",

@@ -11,3 +11,3 @@ "main": "lib/index.js",

"peerDependencies": {
"@tsed/core": "4.34.3"
"@tsed/core": "5.0.0"
},

@@ -28,3 +28,3 @@ "devDependencies": {},

"license": "MIT",
"gitHead": "b6cd4556bd58402429924b7d07f8188f5fb6cc69"
"gitHead": "2ffae0ec9ad3de1e690e053d5e88cc9a577a5954"
}

@@ -5,3 +5,2 @@ export * from "./IInjectableMethod";

export * from "./OnInit";
export * from "./OnInjectorReady";
export * from "./OnDestroy";

@@ -8,0 +7,0 @@ export * from "./ProviderScope";

@@ -1,14 +0,2 @@

import {
Deprecated,
Env,
getClass,
getClassOrSymbol,
Metadata,
nameOf,
promiseTimeout,
prototypeOf,
RegistryKey,
Store,
Type
} from "@tsed/core";
import {Env, getClass, getClassOrSymbol, Metadata, nameOf, promiseTimeout, prototypeOf, RegistryKey, Store, Type} from "@tsed/core";
import {$log} from "ts-log-debug";

@@ -18,9 +6,7 @@ import {Provider} from "../class/Provider";

import {InjectionScopeError} from "../errors/InjectionScopeError";
import {IInjectableMethod, IProvider, ProviderScope} from "../interfaces";
import {IInjectableMethod, ProviderScope} from "../interfaces";
import {IInjectableProperties, IInjectablePropertyService, IInjectablePropertyValue} from "../interfaces/IInjectableProperties";
import {ProviderType} from "../interfaces/ProviderType";
import {GlobalProviders, ProviderRegistry, registerFactory, registerProvider, registerService} from "../registries/ProviderRegistry";
import {GlobalProviders, registerFactory} from "../registries/ProviderRegistry";
let globalInjector: any;
export interface IDISettings {

@@ -63,3 +49,2 @@ get(key: string): any;

super();
globalInjector = this;
this.initInjector();

@@ -492,7 +477,2 @@ }

if (service && eventName in service) {
/* istanbul ignore next */
if (eventName === "$onInjectorReady") {
$log.warn("$onInjectorReady hook is deprecated, use $onInit hook insteadof. See https://goo.gl/KhvkVy");
}
const promise: any = service[eventName](...args);

@@ -537,276 +517,2 @@

}
/**
* Invoke the class and inject all services that required by the class constructor.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const myService = injectorService.invoke<MyService>(MyService);
* }
* }
* ```
*
* @param target The injectable class to invoke. Class parameters are injected according constructor signature.
* @param locals Optional object. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
* @param designParamTypes Optional object. List of injectable types.
* @param requiredScope
* @returns {T} The class constructed.
*/
@Deprecated("removed feature")
/* istanbul ignore next */
static invoke<T>(
target: any,
locals: Map<string | Function, any> = new Map<Function, any>(),
designParamTypes?: any[],
requiredScope: boolean = false
): T {
return globalInjector.invoke(target, locals, designParamTypes, requiredScope);
}
/**
* Construct the service with his dependencies.
* @param target The service to be built.
* @deprecated
*/
@Deprecated("removed feature")
/* istanbul ignore next */
static construct<T>(target: Type<any> | symbol): T {
const provider: Provider<any> = ProviderRegistry.get(target)!;
return this.invoke<any>(provider.useClass);
}
/**
* Emit an event to all service. See service [lifecycle hooks](/docs/services.md#lifecycle-hooks).
* @param eventName The event name to emit at all services.
* @param args List of the parameters to give to each services.
* @returns {Promise<any[]>} A list of promises.
*/
@Deprecated("removed feature")
/* istanbul ignore next */
static async emit(eventName: string, ...args: any[]): Promise<any> {
return globalInjector.emit(eventName, args);
}
/**
* Get a service or factory already constructed from his symbol or class.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const myService = injectorService.get<MyService>(MyService);
* }
* }
* ```
*
* @param target The class or symbol registered in InjectorService.
* @returns {boolean}
*/
@Deprecated("removed feature")
/* istanbul ignore next */
static get<T>(target: RegistryKey): T {
return globalInjector.get(target)!.instance;
}
/**
* Invoke a class method and inject service.
*
* #### IInjectableMethod options
*
* * **target**: Optional. The class instance.
* * **methodName**: `string` Optional. The method name.
* * **designParamTypes**: `any[]` Optional. List of injectable types.
* * **locals**: `Map<Function, any>` Optional. If preset then any argument Class are read from this object first, before the `InjectorService` is consulted.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* class MyService {
* constructor(injectorService: InjectorService) {
* injectorService.invokeMethod(this.method.bind(this), {
* target: this,
* methodName: 'method'
* });
* }
*
* method(otherService: OtherService) {}
* }
* ```
*
* @returns {any}
* @param handler The injectable method to invoke. Method parameters are injected according method signature.
* @param options Object to configure the invocation.
*/
@Deprecated("removed feature")
/* istanbul ignore next */
static invokeMethod(handler: any, options: IInjectableMethod<any> | any[]) {
return globalInjector.invokeMethod(handler, options);
}
/**
* Set a new provider from providerSetting.
* @param provider provide token.
* @param instance Instance
* @deprecated Use registerProvider or registerService or registerFactory instead of
*/
@Deprecated("Use registerService(), registerFactory() or registerProvider() util instead of")
/* istanbul ignore next */
static set(provider: IProvider<any> | any, instance?: any) {
if (!provider.provide) {
provider = {
provide: provider,
type: "factory",
useClass: provider,
instance: instance || provider
};
}
registerProvider(provider);
return InjectorService;
}
/**
* Check if the service of factory exists in `InjectorService`.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
* import MyService from "./services";
*
* class OtherService {
* constructor(injectorService: InjectorService) {
* const exists = injectorService.has(MyService); // true or false
* }
* }
* ```
*
* @param target The service class
* @returns {boolean}
*/
@Deprecated("static InjectorService.has(). Removed feature.")
/* istanbul ignore next */
static has(target: any): boolean {
return globalInjector.has(target);
}
/**
* Initialize injectorService and load all services/factories.
*/
@Deprecated("removed feature")
/* istanbul ignore next */
static async load() {
if (!globalInjector) {
globalInjector = new InjectorService();
}
return globalInjector.load();
}
/**
* Add a new service in the registry. This service will be constructed when `InjectorService`will loaded.
*
* #### Example
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export default class MyFooService {
* constructor(){}
* getFoo() {
* return "test";
* }
* }
*
* InjectorService.service(MyFooService);
* const injector = new InjectorService();
* injector.load();
*
* const myFooService = injector.get<MyFooService>(MyFooService);
* myFooService.getFoo(); // test
* ```
*
* @param target The class to add in registry.
* @deprecated Use registerService or registerFactory instead of.
*/
@Deprecated("Use registerService() util instead of")
/* istanbul ignore next */
static service(target: any) {
return registerService(target);
}
/**
* Add a new factory in `InjectorService` registry.
*
* #### Example with symbol definition
*
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export interface IMyFooFactory {
* getFoo(): string;
* }
*
* export type MyFooFactory = IMyFooFactory;
* export const MyFooFactory = Symbol("MyFooFactory");
*
* InjectorService.factory(MyFooFactory, {
* getFoo: () => "test"
* });
*
* @Service()
* export class OtherService {
* constructor(@Inject(MyFooFactory) myFooFactory: MyFooFactory){
* console.log(myFooFactory.getFoo()); /// "test"
* }
* }
* ```
*
* > Note: When you use the factory method with Symbol definition, you must use the `@Inject()`
* decorator to retrieve your factory in another Service. Advice: By convention all factory class name will be prefixed by
* `Factory`.
*
* #### Example with class
*
* ```typescript
* import {InjectorService} from "@tsed/common";
*
* export class MyFooService {
* constructor(){}
* getFoo() {
* return "test";
* }
* }
*
* InjectorService.factory(MyFooService, new MyFooService());
*
* @Service()
* export class OtherService {
* constructor(myFooService: MyFooService){
* console.log(myFooFactory.getFoo()); /// "test"
* }
* }
* ```
* @deprecated Use registerFactory instead of
*/
@Deprecated("Use registerFactory() util instead of")
/* istanbul ignore next */
static factory(target: any, instance: any) {
return registerFactory(target, instance);
}
}

@@ -813,0 +519,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc