Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

Adds AddTasksAsServices extension method to enable DurableTask types (activities, orchestrators, entities) to participate in DI container validation, allowing dependency resolution errors to surface at startup rather than at runtime.

Changes

  • DurableTaskRegistry: Added internal HashSet<Type> collections tracking types registered via type-based methods (AddActivity(Type), AddOrchestrator(Type), AddEntity(Type))

  • DurableTaskWorkerBuilderExtensions: New AddTasksAsServices(Action<DurableTaskRegistry>) extension that:

    • Executes the configuration callback on a temporary registry to extract types
    • Registers extracted types as transient services in IServiceCollection
    • Forwards the same configuration to AddTasks for worker registration

Usage

builder.Services.AddDurableTaskWorker()
    .AddTasksAsServices(tasks =>
    {
        tasks.AddActivity<MyActivity>();
        tasks.AddOrchestrator<MyOrchestrator>();
        tasks.AddEntity<MyEntity>();
    });

Types registered via factory methods or as singletons are not registered in the container - only type-based registrations participate in DI validation.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Request] Add extension to register all functions as services in DI container</issue_title>
<issue_description># Proposal

Introduce a new AddFuncitonsAsServices extension method on IFunctionsWorkerApplicationBuilder that automatically registers every function class detected by the functions framework in the dependency injection container.

This allows all function classes to participate in the container's self-checking logic during startup of the project, preventing runtime errors much later when actually executing specific functions if dependencies cannot be resolved.

Background

AspNetCore MVC provides a AddControllersAsServices() extension that registers all controllers in the container automatically.

This not only enables things such as being able to decorate controller classes via the container, but more importantly it allows controller classes to participate in the Microsoft DI container self-checking mechanism, which iterates through all services registered in the container and checks whether or not their dependencies can be resolved. This mechanism is enabled by default while in debug mode and allows developers to catch DI-related errors much earlier in the pipeline: the validation error is raised during container construction, instead of only during a specific call to the affected controller action.

My proposal is that a similar extension be created for functions/durable functions, which would allow consumers to easily add all functions as services. A potential name for such extension could be AddFuncitonsAsServices(), for consistency.

While consumers can register functions manually themselves and still have them participate in the container self-check process, this approach is error-prone, creates coupling with the durable tasks library, and potentially duplicates logic: users would be tasked with creating their own logic to "detect" all function classes, which is something that the functions framework already does to perform its main job. The alternative is to manually register each individual function as separate calls, which not only doesn't scale well, but is fairly noisy, leads to situations where some functions are forgotten to be registered (which could then potentially lead to runtime issues being detected only after deployment), and also forces developers to remember to add a registration whenever they create a new function.

If the team is resistant to adding such helper extension, the framework should at least expose discovered functions in some sort of callback so that consumers could then register those types themselves without having to replicate the function detection logic.

This is a spin-off of:

Comments on the Issue (you are @copilot in this section)

@jviau Oh, your request is for Azure Functions as a whole and not just Durable. This request would belong in https://github.com/Azure/azure-functions-dotnet-worker

However, there would be an applicable request for Durable as well, for registering all tasks on DurableTaskRegistry to the IServiceCollection. This issue can be repurposed for that functionality request.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 18, 2025 11:50
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Copilot AI changed the title [WIP] Add extension to register all functions as services in DI container Add AddTasksAsServices extension for registering DurableTask types in DI container Dec 18, 2025
Copilot AI requested a review from YunchuWang December 18, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request] Add extension to register all functions as services in DI container

2 participants