From d2573fa902c4f3b70505740aabd2530824480198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Mon, 26 Feb 2024 15:40:50 +0100 Subject: [PATCH] feat: DI is aware of context that starts it --- kDrive/AppDelegate.swift | 2 +- kDrive/Utils/AppFactoryService.swift | 11 ++++++++++- .../ActionNavigationController.swift | 2 +- kDriveFileProvider/FileProviderExtension.swift | 2 +- .../ShareNavigationViewController.swift | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/kDrive/AppDelegate.swift b/kDrive/AppDelegate.swift index 66cfcb463..a34cd0b12 100644 --- a/kDrive/AppDelegate.swift +++ b/kDrive/AppDelegate.swift @@ -36,7 +36,7 @@ import VersionChecker @main final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDelegate { /// Making sure the DI is registered at a very early stage of the app launch. - private let dependencyInjectionHook = EarlyDIHook() + private let dependencyInjectionHook = EarlyDIHook(context: .app) private var reachabilityListener: ReachabilityListener! private static let currentStateVersion = 4 diff --git a/kDrive/Utils/AppFactoryService.swift b/kDrive/Utils/AppFactoryService.swift index 5b63f7ac8..c922a8992 100644 --- a/kDrive/Utils/AppFactoryService.swift +++ b/kDrive/Utils/AppFactoryService.swift @@ -21,15 +21,24 @@ import InfomaniakDI import kDriveCore import os.log +public enum AppContext { + case app + case actionExtension + case fileProviderExtension + case shareExtension +} + /// Something that loads the DI on init public struct EarlyDIHook { - public init() { + public init(context: AppContext) { // setup DI ASAP let navigationManagerFactory = Factory(type: NavigationManageable.self) { _, _ in NavigationManager() } + // TODO: Insert context in dedicated DI object + os_log("EarlyDIHook") FactoryService.setupDependencyInjection(other: [navigationManagerFactory]) } diff --git a/kDriveActionExtension/ActionNavigationController.swift b/kDriveActionExtension/ActionNavigationController.swift index 0ba42d23a..0cd4090d1 100644 --- a/kDriveActionExtension/ActionNavigationController.swift +++ b/kDriveActionExtension/ActionNavigationController.swift @@ -25,7 +25,7 @@ import VersionChecker final class ActionNavigationController: TitleSizeAdjustingNavigationController { /// Making sure the DI is registered at a very early stage of the app launch. - private let dependencyInjectionHook = EarlyDIHook() + private let dependencyInjectionHook = EarlyDIHook(context: .actionExtension) @LazyInjectService var accountManager: AccountManageable diff --git a/kDriveFileProvider/FileProviderExtension.swift b/kDriveFileProvider/FileProviderExtension.swift index f491fef25..145d17f86 100644 --- a/kDriveFileProvider/FileProviderExtension.swift +++ b/kDriveFileProvider/FileProviderExtension.swift @@ -26,7 +26,7 @@ import RealmSwift final class FileProviderExtension: NSFileProviderExtension { /// Making sure the DI is registered at a very early stage of the app launch. - private let dependencyInjectionHook = EarlyDIHook() + private let dependencyInjectionHook = EarlyDIHook(context: .fileProviderExtension) /// Something to enqueue async await tasks in a serial manner. let asyncAwaitQueue = TaskQueue() diff --git a/kDriveShareExtension/ShareNavigationViewController.swift b/kDriveShareExtension/ShareNavigationViewController.swift index faa3a7483..2c955d31f 100644 --- a/kDriveShareExtension/ShareNavigationViewController.swift +++ b/kDriveShareExtension/ShareNavigationViewController.swift @@ -25,7 +25,7 @@ import VersionChecker final class ShareNavigationViewController: TitleSizeAdjustingNavigationController { /// Making sure the DI is registered at a very early stage of the app launch. - private let dependencyInjectionHook = EarlyDIHook() + private let dependencyInjectionHook = EarlyDIHook(context: .shareExtension) @LazyInjectService var accountManager: AccountManageable