ksoup icon indicating copy to clipboard operation
ksoup copied to clipboard

Support for Multiple Instances and Modularity in Ksoup

Open itboy87 opened this issue 1 year ago • 0 comments

Currently, Ksoup operates with a single global instance, which causes issues for users who want to run multiple engines in a single project (see issue #68) or have more than one Ksoup instance with different configurations. To address this, the proposal is to create a modular structure for Ksoup that allows users to extend functionality through additional modules. This will also enable us to create a separate module for Charset Decoder and improve the overall structure of library modules.

Proposed Changes:

  1. Core Module (ksoup-core):
    Ksoup will have a core module that handles the base functionality without any built-in engines or external dependencies.

  2. Extension Modules:
    Users can add specific extensions to Ksoup for I/O and networking by choosing the following modules:

    • I/O Extensions: kotlinx-io, okio, korlibs-io
    • Network Extensions: ktor2, ktor3, korlibs-network
    • Charset Decoder Extension

    These extensions will be built on top of ksoup-core, making it flexible and customizable for various needs.

  3. Breaking Changes:

    • Single Instance Usage:
      Users can still use ksoup-core without any external dependencies, which will work similarly to the current single-instance setup (Ksoup.*). However, to add more functionality, users must explicitly initialize it with extensions, e.g., Ksoup.addExtension(KotlinxIoExtension()). This will install the extension for the global Ksoup.* instance and add extension functions for the specified library (e.g., kotlinx-io).

    • Multiple Instances Support:
      For users who need multiple instances of Ksoup with different configurations, a separate class will be introduced, allowing for more flexibility. (Details of this implementation are still to be planned.)

Benefits:

  • Decoupling Engines:
    This approach will remove the dependency of the ksoup-core module on specific engines, allowing users to opt-in for the engines they need.

  • Future-Proofing:
    The modular design will make Ksoup more scalable and easier to maintain, providing users with more control over the library's functionality.

itboy87 avatar Sep 14 '24 09:09 itboy87