How to use the typedi.Container.registerPropertyHandler 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 typeorm / typeorm-typedi-extensions / src / decorators / OrmCustomRepository.ts View on Github external
const getValue = () => {
            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);
            return connection.getCustomRepository(cls as any);
        };

        if (index !== undefined) {
            Container.registerParamHandler({ type: target as Function, index: index, getValue: getValue });
        } else {
            Container.registerPropertyHandler({ target: target as Function /* todo: looks like typedi wrong type here */, key: propertyName, getValue: getValue });
        }
    };
}