Repository: expo/expo
File: packages/expo-modules-core/android/src/main/java/expo/modules/kotlin/AppContext.kt (Kotlin)

Code before:

  internal var legacyModulesProxyHolder: WeakReference<NativeModulesProxy>? = null

  private val activityResultsManager = ActivityResultsManager(this)
  internal val appContextActivityResultCaller = DefaultAppContextActivityResultCaller(activityResultsManager)

  init {
    requireNotNull(reactContextHolder.get()) {
      "The app context should be created with valid react context."
    }.apply {
      addLifecycleEventListener(reactLifecycleDelegate)
      addActivityEventListener(reactLifecycleDelegate)

      // Registering modules has to happen at the very end of `AppContext` creation. Some modules need to access
      // `AppContext` during their initialisation, so we need to ensure all `AppContext`'s
      // properties are initialized first. Not having that would trigger NPE.
      registry.register(NativeModulesProxyModule(), null)
      registry.register(JSLoggerModule(), null)

      // Registering modules that were previously provided by legacy FileSystem module.
      legacyModuleRegistry.registerInternalModule(FilePermissionModule())
      legacyModuleRegistry.registerInternalModule(AppDirectoriesModule(this))

      registry.register(modulesProvider)

      // Register inline modules
      registerInlineModulesList()

      logger.info("✅ AppContext was initialized")
    }
  }

  fun onCreate() = trace("AppContext.onCreate") {
    registry.postOnCreate()
  }

  private fun registerInlineModulesList() {
    try {
      val inlineModulesList = Class.forName("inline.modules.ExpoInlineModulesList").getConstructor()
        .newInstance() as ModulesProvider
      registry.register(inlineModulesList)
    } catch (_: ClassNotFoundException) {}
  }

  /**
   * Initializes a JSI part of the module registry.
   * It will be a NOOP if the remote debugging was activated.
   */
  fun installJSIInterop() {
    hostingRuntimeContext.installJSIContext()
  }

Review comment (suggestion):
```suggestion
```
A good function name is enough, don't need to describe what it does 😅 

Code after:
      CoroutineName("expo.modules.MainQueue")
  )

  val registry = ModuleRegistry(this.weak())

  val services = ServicesRegistry(this.weak())

  internal var legacyModulesProxyHolder: WeakReference<NativeModulesProxy>? = null

  private val activityResultsManager = ActivityResultsManager(this)
  internal val appContextActivityResultCaller = DefaultAppContextActivityResultCaller(
    activityResultsManager
  )

  init {
    requireNotNull(reactContextHolder.get()) {
      "The app context should be created with valid react context."
    }.apply {
      legacyModuleRegistry.appContext = this@AppContext

      addLifecycleEventListener(reactLifecycleDelegate)
      addActivityEventListener(reactLifecycleDelegate)

      services.register<FilePermissionService>()
      services.register<AppDirectoriesService>()

      services.register(modulesProvider.getServices())

      // Registering modules has to happen at the very end of `AppContext` creation. Some modules need to access
      // `AppContext` during their initialisation, so we need to ensure all `AppContext`'s
      // properties are initialized first. Not having that would trigger NPE.
      registry.register(NativeModulesProxyModule(), null)
      registry.register(JSLoggerModule(), null)

      registry.register(modulesProvider)

      registerInlineModulesList()

      logger.info("✅ AppContext was initialized")
    }
  }

  fun onCreate() = trace("AppContext.onCreate") {
    registry.postOnCreate()
  }

  private fun registerInlineModulesList() {
    try {
      val inlineModulesList = Class.forName("inline.modules.ExpoInlineModulesList").getConstructor()
        .newInstance() as ModulesProvider
      registry.register(inlineModulesList)