MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / ServiceManager

Class ServiceManager

src/platform/ioc/serviceManager.ts:15–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13 */
14@injectable()
15export class ServiceManager implements IServiceManager {
16 @testOnlyMethod()
17 public getContainer() {
18 return this.container;
19 }
20 constructor(private readonly container: Container) {}
21 public add<T>(
22 serviceIdentifier: identifier<T>,
23 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24 constructor: new (...args: any[]) => T,
25 name?: string | number | symbol | undefined,
26 bindings?: symbol[]
27 ): void {
28 if (name) {
29 this.container.bind<T>(serviceIdentifier).to(constructor).whenTargetNamed(name);
30 } else {
31 this.container.bind<T>(serviceIdentifier).to(constructor);
32 }
33
34 if (bindings) {
35 bindings.forEach((binding) => {
36 this.addBinding(serviceIdentifier, binding);
37 });
38 }
39 }
40 public addFactory<T>(
41 factoryIdentifier: interfaces.ServiceIdentifier<interfaces.Factory<T>>,
42 factoryMethod: interfaces.FactoryCreator<T>
43 ): void {
44 this.container.bind<interfaces.Factory<T>>(factoryIdentifier).toFactory<T>(factoryMethod);
45 }
46
47 public addBinding<T1, T2>(from: identifier<T1>, to: identifier<T2>): void {
48 this.container.bind(to).toService(from);
49 }
50
51 public addSingleton<T>(
52 serviceIdentifier: identifier<T>,
53 // eslint-disable-next-line @typescript-eslint/no-explicit-any
54 constructor: new (...args: any[]) => T,
55 name?: string | number | symbol | undefined,
56 bindings?: symbol[]
57 ): void {
58 if (name) {
59 this.container.bind<T>(serviceIdentifier).to(constructor).inSingletonScope().whenTargetNamed(name);
60 } else {
61 this.container.bind<T>(serviceIdentifier).to(constructor).inSingletonScope();
62 }
63
64 if (bindings) {
65 bindings.forEach((binding) => {
66 this.addBinding(serviceIdentifier, binding);
67 });
68 }
69 }
70
71 public addSingletonInstance<T>(
72 serviceIdentifier: identifier<T>,

Callers

nothing calls this directly

Calls 1

testOnlyMethodFunction · 0.90

Tested by

no test coverage detected