mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
ensure container is init'd
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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()(); }
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user