Add AddTasksAsServices extension for registering DurableTask types in DI container#577
Add AddTasksAsServices extension for registering DurableTask types in DI container#577YunchuWang with Copilot wants to merge 8 commits into
Conversation
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds the AddTasksAsServices extension method to enable DurableTask types (activities, orchestrators, entities) to participate in DI container validation, allowing dependency resolution errors to be detected at startup rather than at runtime.
Key Changes:
- Added internal HashSet collections in
DurableTaskRegistryto track types registered via type-based methods - Implemented
AddTasksAsServicesextension that extracts registered types and registers them as transient services - Added comprehensive test coverage for the new functionality
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Abstractions/DurableTaskRegistry.cs | Added internal HashSet properties to track activity, orchestrator, and entity types |
| src/Abstractions/DurableTaskRegistry.Activities.cs | Modified AddActivity(TaskName, Type) to track type in ActivityTypes collection |
| src/Abstractions/DurableTaskRegistry.Orchestrators.cs | Modified AddOrchestrator(TaskName, Type) to track type in OrchestratorTypes collection |
| src/Abstractions/DurableTaskRegistry.Entities.cs | Modified AddEntity(TaskName, Type) to track type in EntityTypes collection |
| src/Worker/Core/DependencyInjection/DurableTaskWorkerBuilderExtensions.cs | Added AddTasksAsServices extension method with XML documentation and implementation |
| test/Worker/Core.Tests/DependencyInjection/DurableTaskWorkerBuilderExtensionsTests.cs | Added comprehensive test suite including tests for activities, orchestrators, entities, function-based tasks, and worker registration |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot address comments |
|
@copilot update pr description to follow .github/PULL_REQUEST_TEMPLATE.md |
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Updated PR description to follow the template in SummaryWhat changed?
Why is this change needed?This enables DurableTask types to participate in DI container validation, allowing dependency resolution errors to be detected at startup rather than at runtime. This follows the same pattern as ASP.NET Core's Issues / work itemsProject checklist
AI-assisted code disclosure (required)Was an AI tool used? (select one)
If AI was used:
AI verification (required if AI was used):
TestingAutomated tests
Manual validation (only if runtime/behavior changed)
Notes for reviewers
builder.Services.AddDurableTaskWorker()
.AddTasksAsServices(tasks =>
{
tasks.AddActivity<MyActivity>();
tasks.AddOrchestrator<MyOrchestrator>();
tasks.AddEntity<MyEntity>();
}); |
halspang
left a comment
There was a problem hiding this comment.
Does this solve the initial ask of the issue? It seems like we are adding the types, yes, but they were asking specifically about named types.
|
issue is fixed already closing it |

Summary
What changed?
AddTasksAsServicesextension method onIDurableTaskWorkerBuilderthat registers all task types (activities, orchestrators, entities) as transient services in the DI containerHashSet<Type>collections inDurableTaskRegistryto track types registered via type-based methods (AddActivity(Type),AddOrchestrator(Type),AddEntity(Type))Why is this change needed?
This enables DurableTask types to participate in DI container validation, allowing dependency resolution errors to be detected at startup rather than at runtime. This follows the same pattern as ASP.NET Core's
AddControllersAsServices()extension.Issues / work items
Project checklist
AI-assisted code disclosure (required)
Was an AI tool used? (select one)
If AI was used:
src/Abstractions/DurableTaskRegistry.cs- Added HashSet tracking for registered typessrc/Worker/Core/DependencyInjection/DurableTaskWorkerBuilderExtensions.cs- Added AddTasksAsServices extensiontest/Worker/Core.Tests/DependencyInjection/DurableTaskWorkerBuilderExtensionsTests.cs- Added comprehensive unit tests[]tonew HashSet<Type>()tonew()based on code review feedbackAI verification (required if AI was used):
Testing
Automated tests
Manual validation (only if runtime/behavior changed)
Notes for reviewers
AddActivity<T>(),AddOrchestrator<T>()) are registered in DIAddTasks()internally, so tasks are registered with both DI and the workerOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.