diff --git a/src/core/ioc/base.ts b/src/core/ioc/base.ts index 69a6d6b..7542500 100644 --- a/src/core/ioc/base.ts +++ b/src/core/ioc/base.ts @@ -3,7 +3,7 @@ import { Container } from './container'; import * as __Services from '../structures/default-services'; import { UnpackFunction } from '../../types/utility'; import type { Logging } from '../interfaces'; -import { __add_container, __swap_container, useContainerRaw } from './global'; +import { __add_container, __init_container, __swap_container, useContainerRaw } from './global'; export function disposeAll(logger: Logging|undefined) { useContainerRaw() @@ -28,6 +28,8 @@ const dependencyBuilder = (container: Container, excluded: string[] ) => { if(typeof v !== 'function') { container.addSingleton(key, v) } else { + //TODO fixme + //@ts-ignore container.addWiredSingleton(key, (cntr: UnpackedDependencies) => v(cntr)) } }, @@ -83,7 +85,7 @@ async function composeRoot( } export async function makeDependencies (conf: ValidDependencyConfig) { - __swap_container(new Container({ autowire: false })); + await __init_container({ autowire: false }); if(typeof conf === 'function') { const excluded: string[] = []; conf(dependencyBuilder(useContainerRaw(), excluded)); diff --git a/src/core/ioc/global.ts b/src/core/ioc/global.ts index 1f3d6d1..42ff98c 100644 --- a/src/core/ioc/global.ts +++ b/src/core/ioc/global.ts @@ -26,11 +26,12 @@ export function __add_container(key: string, v: object) { * Initiates the global api. * Once this is finished, the Service api and the other global api is available */ -export function __init_container(options: { +export async function __init_container(options: { autowire: boolean; path?: string | undefined; }) { containerSubject = new Container(options); + await containerSubject.ready() } /** diff --git a/src/core/ioc/index.ts b/src/core/ioc/index.ts index 1a03a8e..ab57476 100644 --- a/src/core/ioc/index.ts +++ b/src/core/ioc/index.ts @@ -29,17 +29,17 @@ export function Services(...keys: [...T] } /** - * @since 2.0.0. + * @deprecated * Creates a singleton object. * @param cb */ -export function single(cb: () => T) { return cb; } +export function single(cb: () => T) { return cb(); } /** - * @__PURE__ + * @deprecated * @since 2.0.0 * Creates a transient object * @param cb */ -export function transient(cb: () => () => T) { return cb; } +export function transient(cb: () => () => T) { return cb()(); } diff --git a/src/sern.ts b/src/sern.ts index 3719479..3c62096 100644 --- a/src/sern.ts +++ b/src/sern.ts @@ -11,7 +11,6 @@ interface Wrapper { const __start = (entryPoint: string, wrapper: { defaultPrefix?: string }, dependencies: DependencyList) => { - console.log(entryPoint) import(entryPoint) .then(({ __commands, __events=new Map() }) => { console.log(__commands, __events)