1515
1616import io .dapr .config .Properties ;
1717import io .dapr .durabletask .DurableTaskGrpcWorkerBuilder ;
18+ import io .dapr .durabletask .TaskActivityFactory ;
19+ import io .dapr .durabletask .TaskOrchestrationFactory ;
1820import io .dapr .utils .NetworkUtils ;
1921import io .dapr .workflows .Workflow ;
2022import io .dapr .workflows .WorkflowActivity ;
@@ -80,8 +82,8 @@ public WorkflowRuntime build() {
8082 this .executorService = this .executorService == null ? Executors .newCachedThreadPool () : this .executorService ;
8183 if (instance == null ) {
8284 instance = new WorkflowRuntime (
83- this .builder .withExecutorService (this .executorService ).build (),
84- this .managedChannel , this .executorService );
85+ this .builder .withExecutorService (this .executorService ).build (),
86+ this .managedChannel , this .executorService );
8587 }
8688 }
8789 }
@@ -125,7 +127,7 @@ public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(Class<T> cla
125127 /**
126128 * Registers a Workflow object.
127129 *
128- * @param <T> any Workflow type
130+ * @param <T> any Workflow type
129131 * @param instance the workflow instance being registered
130132 * @return the WorkflowRuntimeBuilder
131133 */
@@ -156,7 +158,7 @@ public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(Clas
156158 * Registers an Activity object.
157159 *
158160 * @param <T> any WorkflowActivity type
159- * @param name Name of the activity to register.
161+ * @param name Name of the activity to register.
160162 * @param clazz Class of the activity to register.
161163 * @return the WorkflowRuntimeBuilder
162164 */
@@ -173,7 +175,7 @@ public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(Stri
173175 /**
174176 * Registers an Activity object.
175177 *
176- * @param <T> any WorkflowActivity type
178+ * @param <T> any WorkflowActivity type
177179 * @param instance the class instance being registered
178180 * @return the WorkflowRuntimeBuilder
179181 */
@@ -184,8 +186,8 @@ public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(T in
184186 /**
185187 * Registers an Activity object.
186188 *
187- * @param <T> any WorkflowActivity type
188- * @param name Name of the activity to register.
189+ * @param <T> any WorkflowActivity type
190+ * @param name Name of the activity to register.
189191 * @param instance the class instance being registered
190192 * @return the WorkflowRuntimeBuilder
191193 */
@@ -199,4 +201,52 @@ public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(Stri
199201 return this ;
200202 }
201203
204+ /**
205+ * Registers a Task Activity using a {@link TaskActivityFactory}.
206+ *
207+ * <p>This method allows advanced use cases where activities are created
208+ * dynamically or require custom instantiation logic instead of relying
209+ * on class-based or instance-based registration.
210+ *
211+ * @param activityName the logical name of the activity to register
212+ * @param taskActivityFactory the factory responsible for creating the activity
213+ * @return the {@link WorkflowRuntimeBuilder}
214+ */
215+ public WorkflowRuntimeBuilder registerTaskActivityFactory (
216+ String activityName ,
217+ TaskActivityFactory taskActivityFactory ) {
218+
219+ this .builder .addActivity (taskActivityFactory );
220+ this .activitySet .add (activityName );
221+ this .activities .add (activityName );
222+
223+ this .logger .info ("Registered Activity: {}" , activityName );
224+
225+ return this ;
226+ }
227+
228+ /**
229+ * Registers a Task Orchestration using a {@link TaskOrchestrationFactory}.
230+ *
231+ * <p>This method is intended for advanced scenarios where orchestrations
232+ * are created programmatically or require custom construction logic,
233+ * rather than being registered via workflow classes or instances.
234+ *
235+ * @param orchestrationName the logical name of the orchestration to register
236+ * @param taskOrchestrationFactory the factory responsible for creating the orchestration
237+ * @return the {@link WorkflowRuntimeBuilder}
238+ */
239+ public WorkflowRuntimeBuilder registerTaskOrchestrationFactory (
240+ String orchestrationName ,
241+ TaskOrchestrationFactory taskOrchestrationFactory ) {
242+
243+ this .builder .addOrchestration (taskOrchestrationFactory );
244+ this .workflows .add (orchestrationName );
245+ this .workflowSet .add (orchestrationName );
246+
247+ this .logger .info ("Registered Workflow: {}" , orchestrationName );
248+
249+ return this ;
250+ }
251+
202252}
0 commit comments