v2.3.0
约 917 字大约 3 分钟
2026-05-19
日期:2026-05-18 类型:Feature / Architecture / Decoupling
变更概述
在本次架构迭代中,我们针对 IDriverFactory 与 IDriverRegistry 职责合并进行了二次演进,设计并实现了一套完全解耦、面向切面的反射驱动装配系统:
- 统一自扫描标记 (
UniconDriverAttribute):引入了自定义特性[UniconDriver(string driverType)],用于修饰具体的南向物理驱动类(如S7Driver,ModbusDriver)。 - 免配置零代码发现 (
DiscoverAndRegisterDrivers):在统一服务IDriverRegistry接口上增加了自动发现功能。该功能不仅扫描当前运行 AppDomain 中的已加载程序集,还智能扫描并主动加载执行目录中的所有UniCon.Drivers.*.dll驱动模块。 - 彻底去除编译时依赖:
- 彻底移除了
src/UniCon.WebServer/Program.cs入口对S7Driver,ModbusDriver,OpcUaDriver,MqttDriver,OpcUaPubSubDriver等物理驱动类名与using命名空间的依赖。 - 实现了高可用、解耦的南向“即插即用 (Plug-and-Play)”插件化架构。
- 彻底移除了
[v2.3.0] - 2026-05-18
Added
- UniconDriverAttribute: Custom attribute for decorating concrete southbound communication driver classes with their protocol alias.
- DiscoverAndRegisterDrivers: Dynamic reflection scanning method inside
IDriverRegistryto automatically discover, load, and register southbound modules acrossAppDomainand output directorydllfiles. - Plug-and-Play Southbound Ecosystem: Allows adding new drivers simply by dropping their compiled
dllinside the execution directory without modifying the host webserver's startup code.
Removed
- Manual Mapping Registrations: Deleted hardcoded manual type mappings in
Program.csand matching compile-time southbound dependencies. - IDriverFactory & DriverFactory (standalone): Removed standalone redundant factory components.
Changed
- CommunicationService: Refactored to inject only the unified single service
IDriverRegistry. - Program.cs: Simplified host startup by calling
driverRegistry.DiscoverAndRegisterDrivers(). - DriverFactoryTests: Refactored xUnit tests to test automated scanning discovery rather than hardcoded registry setups.
------details-----
🔍 Task Details
📌 Current Task Board: 统一整合驱动工厂与注册中心 (Unified Driver Registry & Factory)
🎯 最终目标
- 将独立的
IDriverFactory与IDriverRegistry合并为一个统一的IDriverRegistry接口和DriverRegistry实现,实现活跃实例管理与自动依赖装配工厂的二合一; - 在
ServiceCollectionExtensions.cs中精简为单例注入IDriverRegistry,免去注册多个服务组件的繁琐; - 引入
[UniconDriver]自定义特性和反射自动扫描,实现运行时自装配和完全解耦的即插即用插件化南向生态; - 重构 WebServer 程序启动项、CommunicationService 服务以及单元测试以完全对接合并后的
IDriverRegistry。
📂 涉及文件 (Strictly Locked)
📝 Steps
------details end------
