diff --git a/src/common/di-kludge/di-kludge.ts b/src/common/di-kludge/di-kludge.ts deleted file mode 100644 index 863eca9382..0000000000 --- a/src/common/di-kludge/di-kludge.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2021 OpenLens Authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -import type { DependencyInjectionContainer } from "@ogre-tools/injectable"; - -let kludgeDi: DependencyInjectionContainer; - -export const setDiKludge = (di: DependencyInjectionContainer) => { - kludgeDi = di; -}; - -export const getDiKludge = () => kludgeDi; diff --git a/src/common/di-kludge/get-legacy-singleton/get-legacy-singleton.ts b/src/common/di-kludge/get-legacy-singleton/get-legacy-singleton.ts deleted file mode 100644 index 3ba3ac5d64..0000000000 --- a/src/common/di-kludge/get-legacy-singleton/get-legacy-singleton.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2021 OpenLens Authors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -import type { Injectable } from "@ogre-tools/injectable"; -import { getDiKludge } from "../di-kludge"; - -type Awaited = TMaybePromise extends PromiseLike - ? TValue - : TMaybePromise; - -export const getLegacySingleton = < - TInjectable extends Injectable< - TInstance, - TDependencies, - TInstantiationParameter - >, - TInstance, - TDependencies extends object, - TInstantiationParameter, - TMaybePromiseInstance = ReturnType, ->( - injectableKey: TInjectable, - ) => ({ - createInstance: (): TMaybePromiseInstance extends PromiseLike - ? Awaited - : TMaybePromiseInstance => { - const di = getDiKludge(); - - return di.inject(injectableKey); - }, - - getInstance: (): TMaybePromiseInstance extends PromiseLike - ? Awaited - : TMaybePromiseInstance => { - const di = getDiKludge(); - - return di.inject(injectableKey); - }, - - resetInstance: () => { - const di = getDiKludge(); - - // @ts-ignore - return di.purge(injectableKey); - }, - }); diff --git a/src/extensions/getDiForUnitTesting.ts b/src/extensions/getDiForUnitTesting.ts index 4dfd991271..5460d8887b 100644 --- a/src/extensions/getDiForUnitTesting.ts +++ b/src/extensions/getDiForUnitTesting.ts @@ -26,13 +26,10 @@ import { createContainer, ConfigurableDependencyInjectionContainer, } from "@ogre-tools/injectable"; -import { setDiKludge } from "../common/di-kludge/di-kludge"; export const getDiForUnitTesting = () => { const di: ConfigurableDependencyInjectionContainer = createContainer(); - setDiKludge(di); - getInjectableFilePaths() .map(key => { // eslint-disable-next-line @typescript-eslint/no-var-requires diff --git a/src/main/getDi.ts b/src/main/getDi.ts index 4a81bb9086..2b59923a6c 100644 --- a/src/main/getDi.ts +++ b/src/main/getDi.ts @@ -20,19 +20,13 @@ */ import { createContainer } from "@ogre-tools/injectable"; -import { setDiKludge } from "../common/di-kludge/di-kludge"; -export const getDi = () => { - const di = createContainer( +export const getDi = () => + createContainer( getRequireContextForMainCode, getRequireContextForCommonExtensionCode, ); - setDiKludge(di); - - return di; -}; - const getRequireContextForMainCode = () => require.context("./", true, /\.injectable\.(ts|tsx)$/); diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index a977e70a26..06b0588ae2 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -26,13 +26,10 @@ import { createContainer, ConfigurableDependencyInjectionContainer, } from "@ogre-tools/injectable"; -import { setDiKludge } from "../common/di-kludge/di-kludge"; export const getDiForUnitTesting = () => { const di: ConfigurableDependencyInjectionContainer = createContainer(); - setDiKludge(di); - getInjectableFilePaths() .map(key => { // eslint-disable-next-line @typescript-eslint/no-var-requires diff --git a/src/renderer/components/getDi.tsx b/src/renderer/components/getDi.tsx index 57b82c1ac5..a0e4615a7c 100644 --- a/src/renderer/components/getDi.tsx +++ b/src/renderer/components/getDi.tsx @@ -20,19 +20,13 @@ */ import { createContainer } from "@ogre-tools/injectable"; -import { setDiKludge } from "../../common/di-kludge/di-kludge"; -export const getDi = () => { - const di = createContainer( +export const getDi = () => + createContainer( getRequireContextForRendererCode, getRequireContextForCommonExtensionCode, ); - setDiKludge(di); - - return di; -}; - const getRequireContextForRendererCode = () => require.context("../", true, /\.injectable\.(ts|tsx)$/); diff --git a/src/renderer/components/getDiForUnitTesting.tsx b/src/renderer/components/getDiForUnitTesting.tsx index f182d8131e..4e94d20dae 100644 --- a/src/renderer/components/getDiForUnitTesting.tsx +++ b/src/renderer/components/getDiForUnitTesting.tsx @@ -26,13 +26,10 @@ import { createContainer, ConfigurableDependencyInjectionContainer, } from "@ogre-tools/injectable"; -import { setDiKludge } from "../../common/di-kludge/di-kludge"; export const getDiForUnitTesting = () => { const di: ConfigurableDependencyInjectionContainer = createContainer(); - setDiKludge(di); - getInjectableFilePaths() .map(key => { const injectable = require(key).default;