inversify#ContainerModule TypeScript Examples
The following examples show how to use
inversify#ContainerModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: auto-bind.ts From malagu with MIT License | 6 votes |
export function autoBind(registry?: interfaces.ContainerModuleCallBack): interfaces.ContainerModule {
return new ContainerModule((bind, unbind, isBound, rebind) => {
const metadatas: ComponentMetadata[] = Reflect.getMetadata(METADATA_KEY.component, Reflect) || [];
for (let index = metadatas.length - 1; index >= 0; index--) {
const metadata = metadatas[index];
resolve(metadata, bind, rebind);
}
Reflect.defineMetadata(METADATA_KEY.component, [], Reflect);
const constantMetadata: ConstantOption[] = Reflect.getMetadata(METADATA_KEY.constantValue, Reflect) || [];
constantMetadata.map(metadata => resolveConstant(metadata, bind, rebind));
Reflect.defineMetadata(METADATA_KEY.constantValue, [], Reflect);
if (registry) {
registry(bind, unbind, isBound, rebind);
}
});
}
Example #2
Source File: createContainer.ts From reactant with MIT License | 6 votes |
function autoBindModules() {
return new ContainerModule(
(
bind: interfaces.Bind,
unbind: interfaces.Unbind,
isBound: interfaces.IsBound
) => {
const provideMeta = getMetadata(METADATA_KEY.provide);
const optionalMeta = getMetadata(METADATA_KEY.optional);
for (const [identifier, provide] of provideMeta) {
// default injection without optional module.
if (
(!optionalMeta.has(identifier) ||
lookupOptionalIdentifier(identifier)) &&
!isBound(identifier)
) {
bind(identifier).to(provide);
}
}
}
);
}
Example #3
Source File: application-factory.ts From malagu with MIT License | 5 votes |
static async create(applicationProps: ApplicationProps, ...modules: ContainerModule[]): Promise<Application> {
globalThis.malaguProps = applicationProps;
const container = new Container({ skipBaseClassChecks: true });
container.load(commonModule, autoBind(), ...modules);
ContainerProvider.set(container);
const application = container.get<Application>(Application);
return application;
}