mirror of
https://github.com/morten-olsen/homelab-operator.git
synced 2026-02-08 01:36:28 +01:00
24 lines
537 B
TypeScript
24 lines
537 B
TypeScript
import { LogService } from '../services/log/log.ts';
|
|
|
|
type Dependency<T> = new (services: Services) => T;
|
|
|
|
class Services {
|
|
#instances = new Map<Dependency<unknown>, unknown>();
|
|
constructor() {
|
|
console.log('Constructor', 'bar');
|
|
}
|
|
|
|
public get log() {
|
|
return this.get(LogService);
|
|
}
|
|
|
|
get = <T>(dependency: Dependency<T>): T => {
|
|
if (!this.#instances.has(dependency)) {
|
|
this.#instances.set(dependency, new dependency(this));
|
|
}
|
|
return this.#instances.get(dependency) as T;
|
|
};
|
|
}
|
|
|
|
export { Services };
|