How to use the typedi.Container.registerHandler function in typedi

To help you get started, we’ve selected a few typedi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github w3tecch / express-typescript-boilerplate / src / decorators / EventDispatcher.ts View on Github external
return (object: any, propertyName: string, index?: number): any => {
        const eventDispatcher = new EventDispatcherClass();
        Container.registerHandler({ object, propertyName, index, value: () => eventDispatcher });
    };
}
github typeorm / typeorm-typedi-extensions / src / decorators / InjectConnection.ts View on Github external
return function(object: Object|Function, propertyName: string, index?: number) {
        Container.registerHandler({ object, index, propertyName, value: () => {
            const connectionManager = Container.get(ConnectionManager);
            if (!connectionManager.has(connectionName))
                throw new Error(`Cannot get connection "${connectionName}" from the connection manager. ` +
                  `Make sure you have created such connection. Also make sure you have called useContainer(Container) ` +
                  `in your application before you established a connection and importing any entity.`);

            return connectionManager.get(connectionName);
        }});
    };
}
github typeorm / typeorm-typedi-extensions / src / decorators / InjectRepository.ts View on Github external
if (!propertyType) {
                throw new PropertyTypeMissingError(object, propertyName);
            }
            repositoryType = propertyType;
        }

        switch (repositoryType) {
            case Repository:
            case MongoRepository:
            case TreeRepository:
                if (!entityType) {
                    throw new EntityTypeMissingError(object, propertyName, index);
                }
        }
        
        Container.registerHandler({
            index,
            object,
            propertyName,
            value: () => getRepository(connectionName, repositoryType, entityType!),
        });
    };
}
github santiq / bulletproof-nodejs / src / decorators / eventDispatcher.ts View on Github external
return (object: any, propertyName: string, index?: number): void => {
    const eventDispatcher = new EventDispatcherClass();
    Container.registerHandler({ object, propertyName, index, value: () => eventDispatcher });
  };
}
github w3tecch / express-typescript-boilerplate / src / decorators / Logger.ts View on Github external
return (object, propertyKey, index): any => {
        const logger = new WinstonLogger(scope);
        const propertyName = propertyKey ? propertyKey.toString() : '';
        Container.registerHandler({ object, propertyName, index, value: () => logger });
    };
}
github typeorm / typeorm-typedi-extensions / src / decorators / InjectManager.ts View on Github external
return function(object: Object|Function, propertyName: string, index?: number) {
        Container.registerHandler({ object, index, propertyName, value: () => {
            const connectionManager = Container.get(ConnectionManager);
            if (!connectionManager.has(connectionName))
                throw new Error(`Cannot get connection "${connectionName}" from the connection manager. ` +
                  `Make sure you have created such connection. Also make sure you have called useContainer(Container) ` +
                  `in your application before you established a connection and importing any entity.`);

            const connection = connectionManager.get(connectionName);
            const entityManager = connection.manager;
            if (!entityManager)
                throw new Error(`Entity manager was not found on "${connectionName}" connection. ` +
                  `Make sure you correctly setup connection and container usage.`);

            return entityManager;
        }});
    };
}