|
1 | | -using Microsoft.Extensions.DependencyInjection; |
| 1 | +using Microsoft.Extensions.DependencyInjection; |
2 | 2 | using KitX.Core.Contract.Activity; |
3 | 3 | using KitX.Core.Contract.Announcement; |
4 | 4 | using KitX.Core.Contract.Configuration; |
|
21 | 21 | using KitX.Core.Security; |
22 | 22 | using KitX.Core.Statistics; |
23 | 23 | using KitX.Core.Tasks; |
24 | | -using KitX.Core.Workflow; |
25 | | -using KitX.Core.Workflow.BlockScripting; |
26 | | -using KitX.Core.Workflow.Blueprint; |
27 | 24 | using KitX.Core.Event; |
| 25 | +using KitX.Workflow.Hosting; |
28 | 26 | using Serilog; |
29 | 27 |
|
30 | | -using KitX.Core.Workflow.Conversion; |
31 | 28 | namespace KitX.Core.DI; |
32 | 29 |
|
33 | 30 | /// <summary> |
@@ -60,21 +57,6 @@ public static IServiceCollection AddCoreServices(this IServiceCollection service |
60 | 57 | Log.Information("Registering IPluginService..."); |
61 | 58 | services.AddSingleton<IPluginService, PluginsManager>(); |
62 | 59 |
|
63 | | - // Workflow Services |
64 | | - Log.Information("Registering workflow services..."); |
65 | | - // Individual service implementations (WorkflowScriptService facade used for backward compatibility) |
66 | | - // IBlockScriptService is created via factory to inject RealPluginManager from DI |
67 | | - services.AddSingleton<IBlockScriptService>(provider => |
68 | | - { |
69 | | - var state = WorkflowScriptService.RuntimeState; |
70 | | - var rpm = provider.GetRequiredService<RealPluginManager>(); |
71 | | - var service = new BlockScriptServiceImpl(state, rpm); |
72 | | - Log.Information("[DI] IBlockScriptService created with RealPluginManager. HashCode: {HashCode}", rpm.GetHashCode()); |
73 | | - return service; |
74 | | - }); |
75 | | - services.AddSingleton<IWorkflowPluginService>(sp => WorkflowScriptService.PluginServiceInstance); |
76 | | - services.AddSingleton<IWorkflowManagementService>(sp => WorkflowScriptService.ManagementServiceInstance); |
77 | | - |
78 | 60 | // Activity Services |
79 | 61 | Log.Information("Registering IActivityService..."); |
80 | 62 | services.AddSingleton<IActivityService, ActivityManager>(); |
@@ -116,106 +98,15 @@ public static IServiceCollection AddCoreServices(this IServiceCollection service |
116 | 98 | Log.Information("Registering IDeviceHttpClient..."); |
117 | 99 | services.AddSingleton<IDeviceHttpClient, DeviceHttpClient>(); |
118 | 100 |
|
119 | | - // RealPluginManager must be registered as singleton so that PluginsServer and WorkflowScriptService |
120 | | - // use the same instance. This ensures plugin connection events are properly received. |
121 | | - Log.Information("Registering RealPluginManager..."); |
122 | | - services.AddSingleton<RealPluginManager>(provider => |
123 | | - { |
124 | | - var pluginServer = provider.GetRequiredService<IPluginServer>(); |
125 | | - var eventService = provider.GetRequiredService<IEventService>(); |
126 | | - var deviceDiscoveryService = provider.GetRequiredService<IDeviceDiscoveryService>(); |
127 | | - var deviceServer = provider.GetRequiredService<IDeviceServer>(); |
128 | | - return new RealPluginManager(pluginServer, eventService, deviceDiscoveryService, deviceServer, provider.GetRequiredService<IDeviceHttpClient>()); |
129 | | - }); |
130 | | - |
131 | | - // RealPluginManager is pre-resolved by the caller after BuildServiceProvider(). |
132 | | - |
133 | 101 | // Phase 5: Announcement Service |
134 | 102 | Log.Information("Registering IAnnouncementService..."); |
135 | 103 | services.AddSingleton<IAnnouncementService, AnnouncementManager>(); |
136 | 104 |
|
137 | | - // KCS File Services |
138 | | - Log.Information("Registering IKcsFileService..."); |
139 | | - services.AddSingleton<IKcsFileService, KcsFileService>(); |
140 | | - |
141 | | - // Block Script Services |
142 | | - Log.Information("Registering IBlockScriptParser..."); |
143 | | - services.AddSingleton<IBlockScriptParser, KitX.Core.Workflow.BlockScripting.BlockScriptParser>(provider => |
144 | | - { |
145 | | - var funcRegistry = provider.GetService<BuiltinFunctionRegistry>(); |
146 | | - var service = new KitX.Core.Workflow.BlockScripting.BlockScriptParser(funcRegistry); |
147 | | - return service; |
148 | | - }); |
149 | | - |
150 | | - Log.Information("Registering IBlockScriptExecutor..."); |
151 | | - services.AddSingleton<IBlockScriptExecutor, KitX.Core.Workflow.BlockScripting.BlockScriptExecutor>(provider => |
152 | | - { |
153 | | - var service = new KitX.Core.Workflow.BlockScripting.BlockScriptExecutor(); |
154 | | - // Resolve RealPluginManager from DI to ensure same instance |
155 | | - try |
156 | | - { |
157 | | - var pluginManager = provider.GetRequiredService<RealPluginManager>(); |
158 | | - service.SetPluginManager(pluginManager); |
159 | | - Log.Information("[DI] IBlockScriptExecutor: RealPluginManager HashCode = {HashCode}", pluginManager.GetHashCode()); |
160 | | - } |
161 | | - catch (Exception ex) |
162 | | - { |
163 | | - Log.Error(ex, "[DI] Could not initialize BlockScriptExecutor with RealPluginManager from DI container"); |
164 | | - } |
165 | | - return service; |
166 | | - }); |
167 | | - |
168 | | - Log.Information("Registering IBlockScopeManager..."); |
169 | | - services.AddSingleton<IBlockScopeManager, KitX.Core.Workflow.BlockScripting.BlockScopeManager>(); |
170 | | - |
171 | | - // Blueprint Sub-services (must be registered before IBlueprintService) |
172 | | - Log.Information("Registering Blueprint sub-services..."); |
173 | | - |
174 | | - // Discover and register all IBuiltinFunctionDefinition implementations |
175 | | - var functionRegistry = BuiltinFunctionRegistry.Discover(typeof(BuiltinFunctionRegistry).Assembly); |
176 | | - services.AddSingleton(functionRegistry); |
177 | | - |
178 | | - // NodeRegistry with function registry for dynamic node creation |
179 | | - services.AddSingleton<INodeRegistry>(provider => |
180 | | - { |
181 | | - var reg = provider.GetRequiredService<BuiltinFunctionRegistry>(); |
182 | | - return new NodeRegistry(reg); |
183 | | - }); |
184 | | - |
185 | | - services.AddSingleton<ILayoutService, LayoutService>(); |
186 | | - services.AddSingleton<IBlueprintRenderDataService, BlueprintRenderDataService>(); |
187 | | - |
188 | | - // Blueprint Converters |
189 | | - Log.Information("Registering IBlockScriptToBlueprintConverter..."); |
190 | | - services.AddSingleton<IBlockScriptToBlueprintConverter>(provider => |
191 | | - { |
192 | | - var parser = provider.GetRequiredService<IBlockScriptParser>(); |
193 | | - var nodeRegistry = provider.GetRequiredService<INodeRegistry>(); |
194 | | - var layoutService = provider.GetRequiredService<ILayoutService>(); |
195 | | - var funcRegistry = provider.GetService<BuiltinFunctionRegistry>(); |
196 | | - return new BlockScriptToBlueprintConverter(parser, nodeRegistry, layoutService, funcRegistry!); |
197 | | - }); |
198 | | - Log.Information("Registering IBlueprintToBlockScriptConverter..."); |
199 | | - services.AddSingleton<IBlueprintToBlockScriptConverter, BlueprintToBlockScriptConverter>(); |
200 | | - |
201 | | - // Blueprint Export Strategies — all auto-registered from IBuiltinFunctionDefinition implementations |
202 | | - Log.Information("Registering auto-discovered builtin function export strategies..."); |
203 | | - foreach (var def in functionRegistry.AllDefinitions) |
204 | | - { |
205 | | - services.AddSingleton<INodeExportStrategy>(new BuiltinFunctionExportStrategyAdapter(def)); |
206 | | - } |
207 | | - |
208 | | - // Blueprint Services |
209 | | - Log.Information("Registering IBlueprintService..."); |
210 | | - services.AddSingleton<IBlueprintService, BlueprintService>(); |
211 | | - |
212 | | - // Workflow Storage Service |
213 | | - Log.Information("Registering IWorkflowStorageService..."); |
214 | | - services.AddSingleton<IWorkflowStorageService, WorkflowStorageService>(); |
215 | | - |
216 | | - // Trigger Manager |
217 | | - Log.Information("Registering TriggerManager..."); |
218 | | - services.AddSingleton<TriggerManager>(); |
| 105 | + // Workflow Services — full graph registered by the KitX.Workflow library. |
| 106 | + // This includes RealPluginManager (registered as a singleton so PluginsServer and |
| 107 | + // WorkflowScriptService share the same instance and receive plugin connection events; |
| 108 | + // the caller pre-resolves it after BuildServiceProvider()). |
| 109 | + services.AddKitXWorkflow(); |
219 | 110 |
|
220 | 111 | // IMPORTANT: Do NOT call BuildServiceProvider() here. |
221 | 112 | // The caller is responsible for building the single IServiceProvider and passing it |
|
0 commit comments