[Workflow] Add a non-generic Register method that takes a Type.
Describe the feature
All workflows and activities need to be registered. The current way to do that is by manually adding each of them using the RegisterWorkflow<> or RegisterActivity<> methods respectively. Having to add workflows and activities is tedious and error prone.
A welcome addition would be a Register method that takes a Type and determines at runtime if it is a workflow or an activity, registering it if it passes all of the necessary checks.
This will allow people to do is easily reflect on the assembly and find the workflows and activities and register their types.
Since this only happens once at service startup, performance isn't a goal here.
Release Note
RELEASE NOTE:
@clintsinger There's been a bit of a recent shift away from reflection-based registration as it slows down the startup time of the application (as reflection is heavy, it's done only at runtime and it keeps you from easily trimming the assembly).
My own projects contain dozens of registrations and I was finding myself spending more time removing duplicates and adding missing registrations (errors caught only at runtime) than I cared to.
Rather, a few weeks ago, I open sourced a project through my company that implements a project-wide Metalama aspect to do a compile-time analysis of your project to identify any types that implement either Workflow or WorkflowActivity from the Dapr.Workflow namespace. It introduces a static class that you can use as a method group in the typical workflow registration method and with that, you don't ever have to maintain a list of all the types you want to register - they'll be automatically identified and included with each rebuild.
In other words, where today you might write something like this:
builder.Services.AddDaprWorkflowClient();
builder.Services.AddDaprWorkflow(options => {
options.RegisterWorkflow<OrderProcessingWorkflow>();
options.RegisterActivity<NotifyActivity>();
options.RegisterActivity<ReserveInventoryActivity>();
options.RegisterActivity<ProcessPaymentActivity>();
});
You instead need only include:
builder.Services.AddDaprWorkflowClient();
builder.Services.AddDaprWorkflow(DaprRegistrationHelper.RegisterAllEntities); //That's it!
And it'll Just Work and without all the reflection downsides.