Skip to content

Generated extension methods should be placed in the namespace of the activity/orchestration #428

@BalassaMarton

Description

@BalassaMarton

Currently, the GeneratedDurableTaskExtensions class is placed in the Microsoft.DurableTask namespace, which is cluttering all sorts of IDE features from suggestions to refactoring. It would be better if a separate extensions class was generated for each namespace where the activity and orchestrator classes are, so that only the types from the same or explicitly referenced namespaces are available. After all, we probably import that namespace anyway.

Example

Suppose we have two orchestrations in different namespaces, MyDurableTaskProject.Approvals.ApprovalOrchestration and MyDurableTaskProject.Registrations.RegistrationOrchestration.

Generated code before:

namespace Microsoft.DurableTask
{
    public static class GeneratedDurableTaskExtensions
    {
        /// <inheritdoc cref="IOrchestrationSubmitter.ScheduleNewOrchestrationInstanceAsync"/>
        public static Task<string> ScheduleNewApprovalOrchestrationInstanceAsync(
            this IOrchestrationSubmitter client, MyDurableTaskProject.Approvals.ApprovalOrchestrationParameters input, StartOrchestrationOptions? options = null)
        {
            return client.ScheduleNewOrchestrationInstanceAsync("MyDurableTaskProject.Approvals.ApprovalOrchestration", input, options);
        }

        /// <inheritdoc cref="IOrchestrationSubmitter.ScheduleNewOrchestrationInstanceAsync"/>
        public static Task<string> ScheduleNewRegistrationOrchestrationInstanceAsync(
            this IOrchestrationSubmitter client, MyDurableTaskProject.Registrations.RegistrationOrchestrationParameters input, StartOrchestrationOptions? options = null)
        {
            return client.ScheduleNewOrchestrationInstanceAsync("MyDurableTaskProject.Registrations.RegistrationOrchestration", input, options);
        }
}

After the change, it should be like this:

using Microsoft.DurableTask;

namespace MyDurableTaskProject.Approvals
{
    public static class GeneratedDurableTaskExtensions
    {
        /// <inheritdoc cref="IOrchestrationSubmitter.ScheduleNewOrchestrationInstanceAsync"/>
        public static Task<string> ScheduleNewApprovalOrchestrationInstanceAsync(
            this IOrchestrationSubmitter client, ApprovalOrchestrationParameters input, StartOrchestrationOptions? options = null)
        {
            return client.ScheduleNewOrchestrationInstanceAsync("MyDurableTaskProject.Approvals.ApprovalOrchestration", input, options);
        }
}

namespace MyDurableTaskProject.Registrations
{
    public static class GeneratedDurableTaskExtensions
    {
        /// <inheritdoc cref="IOrchestrationSubmitter.ScheduleNewOrchestrationInstanceAsync"/>
        public static Task<string> ScheduleNewRegistrationOrchestrationInstanceAsync(
            this IOrchestrationSubmitter client, RegistrationOrchestrationParameters input, StartOrchestrationOptions? options = null)
        {
            return client.ScheduleNewOrchestrationInstanceAsync("MyDurableTaskProject.Registrations.RegistrationOrchestration", input, options);
        }
}

Metadata

Metadata

Assignees

Labels

P2source generatorsIssue relates to the source generator project(s)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions