ensure container is init'd

This commit is contained in:
jacob
2024-05-09 20:42:09 -05:00
parent 08ef80522f
commit ffb2872f8b
4 changed files with 10 additions and 8 deletions

View File

@@ -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));

View File

@@ -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()
}
/**

View File

@@ -29,17 +29,17 @@ export function Services<const T extends (keyof Dependencies)[]>(...keys: [...T]
}
/**
* @since 2.0.0.
* @deprecated
* Creates a singleton object.
* @param cb
*/
export function single<T>(cb: () => T) { return cb; }
export function single<T>(cb: () => T) { return cb(); }
/**
* @__PURE__
* @deprecated
* @since 2.0.0
* Creates a transient object
* @param cb
*/
export function transient<T>(cb: () => () => T) { return cb; }
export function transient<T>(cb: () => () => T) { return cb()(); }

View File

@@ -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)