Dynamic plug-in loading method and system
By employing plugin description files and a dependency injection framework in the industrial automation host computer software, dynamic loading and decoupling of plugins from the main program are achieved. This solves the problems of coupling and configuration complexity in existing plugin mechanisms, improves the system's scalability and maintainability, and supports hot-plugging and deep linkage of plugins.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-12
- Publication Date
- 2026-04-07
AI Technical Summary
Existing industrial automation host computer software suffers from problems such as high coupling and compilation dependency, complex configuration, opaque loading mechanism, and lack of integration management mechanism, resulting in insufficient system scalability, flexibility, and maintainability.
Plugins are described using predefined plugin description file formats (such as Json, YAML, XML, INI, Toml, Csv). Utilizing dependency injection and a modular framework, plugins are dynamically loaded and decoupled from the main program, supporting hot-plugging of plugins at runtime and event-driven communication.
It achieves physical and logical decoupling between the plugin and the main program, improves the system's flexibility and maintainability, simplifies the configuration process, supports online expansion and updates, and enhances the linkage between the plugin and the main program.
Smart Images

Figure CN121807400A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software technology, and in particular to a dynamic plug-in loading method and system. Background Technology
[0002] In the field of industrial automation, the development of programmable logic controllers (PLCs) typically relies on host computer software. One of the core functions of this type of software is to translate the program written by the user in a high-level programming language (such as ladder diagrams, function block diagrams, structured text, etc.) into machine code or intermediate code that the PLC's CPU can directly execute, in a single step within the development environment through static compilation.
[0003] However, this static design philosophy has also extended to the functional architecture of many host computer software programs. Currently, many industrial automation host computer software programs integrate their functional modules using static linking and compilation. This means that all functions are fixed in the main program before the software is released, resulting in significant bottlenecks in the system's scalability, flexibility, and maintainability.
[0004] Although there are some plug-in mechanisms in the existing technology designed to enhance scalability, they generally suffer from one or more of the following inherent drawbacks: 1. High coupling and compilation dependency: The coupling between the plugin and the main program is too high. Adding, modifying or updating any plugin requires recompiling and republishing the entire main program, which makes it impossible to achieve true runtime dynamic expansion.
[0005] 2. Complex and inconsistent configuration processes: There is a lack of a lightweight, standardized plugin description specification. Plugin configuration often relies on hard-coded or cumbersome configuration files, increasing development and management complexity and hindering batch deployment and automated management of plugins.
[0006] 3. The loading mechanism is opaque and lacks dynamic management capabilities: The loading process of plugins is not transparent to the system, making it difficult to achieve hot-swapping of plugins (i.e., enabling, disabling or updating plugins without restarting the main program), which limits the continuous operation capability and availability of the system.
[0007] 4. Lack of integrated management mechanism: There is a lack of a unified registration, management and communication framework for the user interface elements (such as function buttons and menus) provided by the plugins and the event response mechanism between the plugins and the main program, resulting in a fragmented integrated experience and difficulty in achieving deep functional linkage.
[0008] Therefore, there is an urgent need to provide a method and system for loading dynamic plugins. Summary of the Invention
[0009] To address the above issues, this invention provides a dynamic plugin loading method and system that dynamically integrates plugin interfaces and function buttons into the main program, achieving complete physical and logical decoupling between the plugin and the main program. The plugin and the main program can be developed, compiled, tested, and deployed independently.
[0010] According to a first aspect of the present invention, a dynamic plugin loading method is provided, comprising: S1. When the main program starts up or runs, it reads and parses the predefined plugin description file; S2. Based on the information specified in the plugin description file, dynamically locate and load the corresponding plugin dynamic link library; S3. Using dependency injection and a modular framework, initialize the plugin in the plugin dynamic link library that can implement the plugin description file function, and integrate the plugin into the main program's runtime environment. S4. Parse the set of function items defined in the plugin description file, and dynamically generate the corresponding function trigger controls in the user interface of the main program according to the definition of the set of function items. S5. Based on the user's operation on the function trigger control, execute the instructions associated with the function trigger control in the plugin description file.
[0011] In the above scheme, in step S1, the format of the predefined plugin description file includes one or more of Json, YAML, XML, INI, Toml, and Csv.
[0012] In the above scheme, in step S1, the plugin description file includes: plugin name field, path field, class name field and icon field, wherein the icon field is used to store plugin icon data, and the icon data is stored in Base64 encoding format.
[0013] In the above scheme, step S2 includes: S21. Add the plugin to the directory based on the path and class name information in the plugin description file; S22. Traverse the directory, obtain the plugin type based on the class name field and reflection mechanism, and dynamically load the plugin dynamic link library.
[0014] In the above scheme, step S3 includes: S31. Using dependency injection and modular framework, plugins are processed through a dependency injection container to obtain instances; S32. Call the instance's initialization method to activate the plugin and integrate it into the main program's runtime environment.
[0015] In the above scheme, in step S4, the definition of each function item in the function item set includes: the display name of the function button, the icon data of the function button, the hover tooltip of the function button, and the execution instruction.
[0016] In the above scheme, step S4 involves dynamically generating corresponding function trigger controls in the main program's user interface, including: In the main view model of the main program, the plugin description file is parsed, and the function triggering control is rendered as the corresponding item on the main interface according to the type field in the plugin description file.
[0017] In the above scheme, the instructions associated with the function triggering control in the plugin description file in step S4 include: Register the user interface view to the main program's region management; Register the data model or service into the main program's dependency injection container; Subscribe to application-level events published by the main program.
[0018] The dynamic plug-in loading method according to any one of the above schemes is applied to the extension of automotive architecture.
[0019] According to a second aspect of the present invention, a dynamic plug-in loading system is provided, the system being used to implement the method described in any one of the above solutions, the system comprising: The reading module is used by the main program to read and parse predefined plugin description files at startup or runtime; The plugin loading module is used to dynamically locate and load the corresponding plugin dynamic link library based on the path information specified in the plugin description file. The plugin integration module is used to initialize the plugins implemented in the plugin dynamic link library using dependency injection and modular framework, and integrate the plugins into the main program's runtime environment. The plugin parsing module is used to parse the set of function items defined in the plugin description file, and dynamically generate the corresponding function trigger controls in the user interface of the main program based on the definition of the set of function items. The execution module is used to execute the instructions associated with the function trigger control in the plugin description file based on the user's operation on the function trigger control.
[0020] The beneficial effects of this invention are: Modularization and decoupling: Collaboration through predefined interfaces and configuration files achieves complete physical and logical decoupling between plugins and the main program. Plugins and the main program can be developed, compiled, tested, and deployed independently, significantly improving team collaboration efficiency and system maintainability for large-scale software.
[0021] Dynamic loading: The main program dynamically loads plugins at runtime via reflection and modular directories, enabling online expansion, updates, or removal of functionality without recompiling or restarting the main program. This provides hot-swappable support for applications requiring high continuity, such as industrial automation, greatly improving system flexibility and availability.
[0022] Flexible configuration: A structured plugin description file is used as the sole information source, enabling unified management of all plugin metadata in a declarative manner. This not only simplifies the plugin registration process but also makes modifying plugin icons, display positions, function buttons, and prompts extremely easy; changes only require modifying the configuration file to take effect, achieving an advanced architecture of configuration-driven UI.
[0023] Event-driven: Plugins can subscribe to global events published by the main program, thus deeply integrating into the main program's business processes. This loosely coupled event-driven pattern enables seamless interaction and data exchange between plugins and the main program, as well as between plugins themselves, going beyond simple interface integration.
[0024] High compatibility: Supports mainstream technology stacks such as C# WPF, DevExpress controls, and the Prism framework. This ensures the stability and testability of the solution and provides development teams with a familiar and low-learning-cost technology path. Attached Figure Description
[0025] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.
[0026] Figure 1 A flowchart of a dynamic plugin loading method provided in an embodiment of the present invention; Figure 2 This is a flowchart illustrating the operation of a dynamic plugin loading method provided in an embodiment of the present invention.
[0027] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0028] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0029] The terms "first," "second," etc., used in this disclosure are for distinguishing similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented, for example, in orders other than those illustrated or described herein.
[0030] Furthermore, the terms “comprising” and “having”, and any variations thereof, are intended to cover non-exclusive inclusion, such that a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to such process, method, product, or apparatus.
[0031] Multiple, including two or more.
[0032] And / or, it should be understood that, for the purposes of this disclosure, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0033] like Figure 1 and Figure 2 As shown, one embodiment of the present invention provides a dynamic plugin loading method, including: S1. When the main program starts up or runs, it reads and parses the predefined plugin description file; S2. Based on the path information specified in the plugin description file, dynamically locate and load the corresponding plugin dynamic link library; S3. Using dependency injection and a modular framework, initialize the plugin implemented in the plugin dynamic link library and integrate the plugin into the main program's runtime environment. S4. Parse the set of function items defined in the plugin description file, and dynamically generate the corresponding function trigger controls in the user interface of the main program according to the definition of the set of function items. S5. Based on the user's operation on the function trigger control, execute the instructions associated with the function trigger control in the plugin description file.
[0034] In step S1, the predefined plugin description file format includes one or more of the following: JSON, YAML, XML, INI, Tomml, and Csv. It supports multiple configuration file formats, is independent of a specific technology stack, and adapts to the preferences of different development teams and existing system configuration specifications.
[0035] In step S1, the plugin description file includes: a plugin name field, a path field, a class name field, and an icon field. The name field uniquely identifies the plugin, the path field specifies the storage location of the plugin's dynamic link library file, the class name field specifies the plugin's entry class, and the icon field stores the plugin icon data in Base64 encoding. This standardizes and improves the readability of plugin information, greatly simplifying the plugin registration and management process.
[0036] In this embodiment, the plugin configuration is read via JSON serialization in App.xaml.cs (the application startup entry point).
[0037] Step S2 includes: S21. Using the dependency injection and modular framework (Prism framework) provided by IModuleCatalog (module interface), add the plugin to the directory programmatically according to the path and class name information in the plugin description file; S22. Through dependency injection and the module manager of the modular framework, the directory is traversed, and the type of the plugin is obtained based on the class name field and the reflection mechanism, and the plugin dynamic link library is dynamically loaded.
[0038] In this embodiment, plugins are presented in a modular form. The main program dynamically loads dynamic link libraries at runtime based on path information, achieving physical and logical decoupling between plugins and the main program. Adding a new plugin only requires providing a new dynamic link library and an updated description file; no modification or recompilation of the main program is needed. Plugin dynamic link libraries can be deployed in a unified directory or custom subdirectories via path configuration, providing great flexibility for plugin organization, distribution, and updates. The main program can precisely control the activation timing and execution context of plugins, avoiding unnecessary resource consumption and startup delays.
[0039] Step S3 includes: S31. Using dependency injection and modular framework, plugins are processed through a dependency injection container to obtain instances; S32. Call the instance's initialization method to activate the plugin and integrate it into the main program's runtime environment.
[0040] In step S3, the plugin is activated and integrated by calling the initialization method of its entry class. This utilizes the module interface within the dependency injection and modular framework, and ensures that all plugins follow a consistent integration pattern by registering their services, views, and models upon plugin startup.
[0041] Furthermore, during plugin initialization, event handlers can be registered with the main program to subscribe to and respond to specific events published by the main program during its operation, enabling bidirectional communication and data linkage between the plugin and the main program. These specific events include: project files being opened, project files being saved, project files being closed, application configuration changes, or other custom events defined by the main program.
[0042] After the plugin is initialized, its functions are perceived and managed by the main program's area manager, achieving an integrated experience that is no different from the main program's native functions.
[0043] In step S4, the definition of each function item in the function item set includes: the display name of the function button, the icon data of the function button, the hover tooltip of the function button, and the execution instruction.
[0044] In step S4, the corresponding function trigger controls are dynamically generated in the user interface of the main program, including: The main view model of the main program is parsed, and based on the type field in the plugin description file, it is determined whether to render the function trigger control as a large icon button on the main interface or as a sub-menu item under the tool menu.
[0045] In step S4, the instructions associated with the function triggering control in the plugin description file include: Register the user interface view to the main program's region management; Register the data model or service into the main program's dependency injection container; Subscribe to application-level events published by the main program.
[0046] In this embodiment, the parsed set of function items is dynamically used to generate menu buttons in the MainWindowViewModel of the main program. The interface structure (buttons, menus) is driven by a description file, rather than hard-coded in XAML (Extensible Application Markup Language) or ViewModel. Changing the interface layout does not require modifying the code; only the configuration file needs to be updated. Plugin fields allow for flexible control over whether controls are used as large icons on the main interface or as tool menu items, adapting to different user experience designs.
[0047] In step S5, the main program can centrally handle all plugin function calls through a unified execution entry point, facilitating the addition of cross-cutting concerns such as logging, permission verification, and exception handling. Commands are not limited to opening interfaces; they can also perform deeper operations such as registering views, registering services, and subscribing to events, enabling plugins to interact closely with the core processes of the main program. Based on a publish / subscribe pattern using an event aggregator (such as Prism's EventAggregator), loosely coupled communication is achieved between plugins and the main program, and between plugins themselves, enhancing the system's scalability and maintainability.
[0048] It should be noted that the plugin description file can be reloaded during application runtime, thereby enabling hot-swappable plugin management. Plugin functions can be enabled, disabled, or updated without restarting the main program.
[0049] This embodiment uses a description file to drive the interface structure, such as buttons and menus, rather than hard-coding. Changing the interface layout requires no code modification, only an update to the configuration file. The type field allows flexible control over whether controls are displayed as large icons on the main interface or as tool menu items, adapting to different user experience designs. Hover tooltips can be configured for each function item, enhancing the software's usability and professionalism.
[0050] It should be noted that the main program in this invention is built on the C# programming language and the WPF framework, and uses the Prism framework as the basic architecture for its modular development and dependency injection; the plugin dynamic link library is an assembly compiled on the .NET platform.
[0051] According to a second aspect of the present invention, a dynamic plug-in loading system is provided, the system being used to implement the method described in any one of the above solutions, the system comprising: The reading module is used by the main program to read and parse predefined plugin description files at startup or runtime; The plugin loading module is used to dynamically locate and load the corresponding plugin dynamic link library based on the path information specified in the plugin description file. The plugin integration module is used to initialize the plugins implemented in the plugin dynamic link library using dependency injection and modular framework, and integrate the plugins into the main program's runtime environment. The plugin parsing module is used to parse the set of function items defined in the plugin description file, and dynamically generate the corresponding function trigger controls in the user interface of the main program based on the definition of the set of function items. The execution module is used to execute the instructions associated with the function trigger control in the plugin description file based on the user's operation on the function trigger control.
[0052] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0053] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0054] Through the above description of the embodiments, those skilled in the art can clearly understand that the above implementation methods can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0055] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims. All of these forms are within the protection scope of the present invention.
Claims
1. A dynamic plugin loading method, characterized in that, include: S1. When the main program starts up or runs, it reads and parses the predefined plugin description file; S2. Based on the information specified in the plugin description file, dynamically locate and load the corresponding plugin dynamic link library; S3. Using dependency injection and a modular framework, initialize the plugin in the plugin dynamic link library that can implement the plugin description file function, and integrate the plugin into the main program's runtime environment. S4. Parse the set of function items defined in the plugin description file, and dynamically generate the corresponding function trigger controls in the user interface of the main program according to the definition of the set of function items. S5. Based on the user's operation on the function trigger control, execute the instructions associated with the function trigger control in the plugin description file.
2. The dynamic plugin loading method according to claim 1, characterized in that, In step S1, the format of the predefined plugin description file includes one or more of the following: JSON, YAML, XML, INI, Toml, and Csv.
3. The dynamic plugin loading method according to claim 1, characterized in that, In step S1, the plugin description file includes: plugin name field, path field, class name field and icon field. The icon field is used to store plugin icon data, and the icon data is stored in Base64 encoding format.
4. The dynamic plugin loading method according to claim 3, characterized in that, Step S2 includes: S21. Add the plugin to the directory based on the path and class name information in the plugin description file; S22. Traverse the directory, obtain the plugin type based on the class name field and reflection mechanism, and dynamically load the plugin dynamic link library.
5. The dynamic plugin loading method according to claim 3, characterized in that, Step S3 includes: S31. Using dependency injection and modular framework, plugins are processed through a dependency injection container to obtain instances; S32. Call the instance's initialization method to activate the plugin and integrate it into the main program's runtime environment.
6. The dynamic plugin loading method according to claim 1, characterized in that, In step S4, the definition of each function item in the function item set includes: the display name of the function button, the icon data of the function button, the hover tooltip of the function button, and the execution instruction.
7. The dynamic plugin loading method according to claim 3, characterized in that, In step S4, the corresponding function trigger controls are dynamically generated in the user interface of the main program, including: In the main view model of the main program, the plugin description file is parsed, and the function triggering control is rendered as the corresponding item on the main interface according to the type field in the plugin description file.
8. The dynamic plugin loading method according to claim 1, characterized in that, In step S4, the instructions associated with the function trigger control in the plugin description file include: Register the user interface view to the main program's region management; Register the data model or service into the main program's dependency injection container; Subscribe to application-level events published by the main program.
9. The dynamic plugin loading method according to any one of claims 1-8, characterized in that, Applications to automotive architecture extensions.
10. A dynamic plug-in loading system, characterized in that, The system is used to implement the method as described in any one of claims 1-8, the system comprising: The reading module is used by the main program to read and parse predefined plugin description files at startup or runtime; The plugin loading module is used to dynamically locate and load the corresponding plugin dynamic link library based on the path information specified in the plugin description file. The plugin integration module is used to initialize the plugins implemented in the plugin dynamic link library using dependency injection and modular framework, and integrate the plugins into the main program's runtime environment. The plugin parsing module is used to parse the set of function items defined in the plugin description file, and dynamically generate the corresponding function trigger controls in the user interface of the main program based on the definition of the set of function items. The execution module is used to execute the instructions associated with the function trigger control in the plugin description file based on the user's operation on the function trigger control.