Plugin Mechanism and Extensions
1. Overview
The plugin mechanism of the system allows developers to extend system functionality in a loosely coupled manner. Through standard interfaces and dynamic loading technologies, the system can identify and activate external components at runtime.
2. Architecture Design
- Host: The main application responsible for initializing the environment, loading plugins, and providing core services.
- Plugin Interface (Contract): Shared libraries defining the interaction standards between plugins and the host.
- Plugin Implementation: Separate assemblies containing concrete business logic or functional extensions.
3. Plugin Lifecycle
- Discovery: The host scans the specified path.
- Loading: Loads the assembly into memory.
- Registration: Registers services in the IoC container and executes the Module
ConfigureServicesmethod. - Initialization: Executes the Module
OnApplicationInitializationmethod. - Running: The plugin services interact with the host.
- Unloading: (Optional) Release resources when the application stops.
4. Extension Points
4.1 API Extensions
Plugins can contain independent Controllers, and the system automatically discovers and registers routes.
4.2 UI Extensions
If the frontend also supports modularity, backend plugins can serve static resources or provide UI configuration data.
4.3 Background Task Extensions
Plugins can register their own background worker threads (BackgroundWorker).
4.4 Event Handling
Plugins can subscribe to events published by the host (EventBus) to perform decoupled business logic.
5. Development Guidelines
- Create Plugin Project: Create a new Class Library project.
- Add Dependencies: Reference
Lmes.Coreor related Contract projects. - Define Module: Create a class inheriting from
AbpModule. - Implement Features: Write Services, Controllers, etc.
- Build and Deploy: Compile the generated DLL and place it in the host's Plugin directory.
6. Security Isolation
- Plugins operate within the same process as the host.
- Be cautious of malicious plugins affecting system stability.
- It is recommended to strictly review plugin sources in production environments.