Support for Multiple Instances and Modularity in Ksoup
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:
-
Core Module (ksoup-core):
Ksoup will have a core module that handles the base functionality without any built-in engines or external dependencies. -
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. - I/O Extensions:
-
Breaking Changes:
-
Single Instance Usage:
Users can still useksoup-corewithout 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 globalKsoup.*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 theksoup-coremodule 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.