|
| 1 | +/********************************************************************** |
| 2 | + * Copyright (C) 2025 Red Hat, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + ***********************************************************************/ |
| 18 | + |
| 19 | +import 'reflect-metadata'; |
| 20 | + |
| 21 | +import type { ExtensionContext as PodmanDesktopExtensionContext, TelemetryLogger } from '@podman-desktop/api'; |
| 22 | +import { Container } from 'inversify'; |
| 23 | + |
| 24 | +import { ExtensionContextSymbol, TelemetryLoggerSymbol } from '/@/inject/symbol'; |
| 25 | +import { RpcExtension } from '/@common/rpc/rpc'; |
| 26 | +import { managersModule } from '/@/manager/_manager-module'; |
| 27 | + |
| 28 | +export class InversifyBinding { |
| 29 | + #container: Container | undefined; |
| 30 | + |
| 31 | + readonly #rpcExtension: RpcExtension; |
| 32 | + |
| 33 | + readonly #extensionContext: PodmanDesktopExtensionContext; |
| 34 | + |
| 35 | + readonly #telemetryLogger: TelemetryLogger; |
| 36 | + |
| 37 | + constructor( |
| 38 | + rpcExtension: RpcExtension, |
| 39 | + extensionContext: PodmanDesktopExtensionContext, |
| 40 | + telemetryLogger: TelemetryLogger, |
| 41 | + ) { |
| 42 | + this.#rpcExtension = rpcExtension; |
| 43 | + this.#extensionContext = extensionContext; |
| 44 | + this.#telemetryLogger = telemetryLogger; |
| 45 | + } |
| 46 | + |
| 47 | + public async initBindings(): Promise<Container> { |
| 48 | + this.#container = new Container(); |
| 49 | + |
| 50 | + this.#container.bind(RpcExtension).toConstantValue(this.#rpcExtension); |
| 51 | + this.#container.bind(ExtensionContextSymbol).toConstantValue(this.#extensionContext); |
| 52 | + this.#container.bind(TelemetryLoggerSymbol).toConstantValue(this.#telemetryLogger); |
| 53 | + |
| 54 | + await this.#container.load(managersModule); |
| 55 | + |
| 56 | + return this.#container; |
| 57 | + } |
| 58 | + |
| 59 | + async dispose(): Promise<void> { |
| 60 | + if (this.#container) { |
| 61 | + await this.#container.unbindAll(); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments