Innovian.Dapr.Workflow.RegistrationAspect 2024.10.29.1

dotnet add package Innovian.Dapr.Workflow.RegistrationAspect --version 2024.10.29.1                
NuGet\Install-Package Innovian.Dapr.Workflow.RegistrationAspect -Version 2024.10.29.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Innovian.Dapr.Workflow.RegistrationAspect" Version="2024.10.29.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Innovian.Dapr.Workflow.RegistrationAspect --version 2024.10.29.1                
#r "nuget: Innovian.Dapr.Workflow.RegistrationAspect, 2024.10.29.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Innovian.Dapr.Workflow.RegistrationAspect as a Cake Addin
#addin nuget:?package=Innovian.Dapr.Workflow.RegistrationAspect&version=2024.10.29.1

// Install Innovian.Dapr.Workflow.RegistrationAspect as a Cake Tool
#tool nuget:?package=Innovian.Dapr.Workflow.RegistrationAspect&version=2024.10.29.1                

<a href="https://innovian.net"> <p align="center"> <img src="https://innovian.net/img/bluelogo.svg" width="100px"/> </p> </a>

Innovian.Dapr.Workflow.RegistrationAspect

Build Status NuGet

This project is provided to the larger open-source community by Innovian.

This solution implements an aspect using Metalama targeting .NET 8 that provides a utility intended for use with Dapr Workflows. When using .NET, the expected approach is to register the various Workflow and Workflow Activities in the DI registration process, but this can be cumbersome and time-consuming to maintain, especially in projects surfacing a great many such types. Rather than rely on a reflection-based approach to locate each of these types during startup, this aspect provides the same capability but at compilation time, ensuring that all Workflow and Workflow Activities in the project are properly registered in DI as expected, limiting the potential for developer error and bugs that show up online at runtime.

What does it do?

The attribute performs the following:

  • Introduces a new class into the project with the namespace <Program namespace>.DaprUtilities where <Program namespace> is the namespace used in your Program.cs file within a public, partial, static class called DaprRegistrationHelper.
  • Introduces a new method into this type named "DaprRegistrationHelper".
  • When provided with a list of Workflows and Workflow Activities from the Fabric, this will introduce a registration for each into the introduced method.

Usage

While a package is available on NuGet for the attribute itself, it's intended that the target developer only utilize the Fabric to apply this attribute. This is because it's the Fabric that locates the Workflow and Workfow Activity types in the project and compiles them for the attribute to build the registration method in the target type. Applying the attribute directly to a DaprRegistrationHelper class will only introduce the RegisterAllEntities method, but will not actually register any of the Workflows or Workflow Activities.

The Fabric identifies Workflows by looking for those types in the project that implement an abstract base type called "Workflow" and identifies Workflow Activities by looking for those types in the project that implement an abstract base type called "WorkflowActivity".

Metalama License

The team at Postsharp were kind enough to grant this project an open source license meaning that this namespace can be built with any number of aspects without a Metalama license. However, you will a Metalama license to use this in your own project. Their free license allows up to 3 aspects at no cost. I've purchased a commercial license for their software for use at my own company and if you similarly find that this aspects adds sufficient value to your own work, I encourage you to purchase licenses for your own team.

Installation

Using the .NET CLI tools:

dotnet add package Innovian.Dapr.Workflow.RegistrationAspect

Using the Package Manager Console:

Install-Package Innovian.Dapr.Workflow.RegistrationAspect

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on the project within your solution you wish to add the attribute to.
  3. Click on "Manage NuGet Packages...".
  4. Click on the "Browse" tab and search for "Innovian.Dapr.Workflow.RegistrationAspect".
  5. Click on the "Innovian.Dapr.Workflow.RegistrationAspect" package, select the appropriate version in the right-tab and click Install.

Usage

No additional effort is necessary beyond installation of the Innovian.Dapr.Workflow.RegistrationAspect package on the project to configure the fabric or the applied aspect. It will automatically identify all each of the Workflow and Workflow Activities in the project, introduce the static type DaprRegistrationHelper and a static method called RegisterAllEntities. Because it's not yet possible to modify statements within a method at this time, registration is left as an exercise to the use of both the Dapr Workflow client and the Dapr Workflows (via the introduced static method).

For example, let's say you've got a simple Program.cs and you want to register everything for Dapr. You'd start off with the following:

using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

And to register your Dapr workflows, simply update to reflect the following (note your namespace will likely vary based on your own Program.cs namespace):

using Dapr.Workflow;
using DaprUtilities;
using Microsoft.AspNetCore.Builder;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDaprWorkflowClient();
builder.Services.AddDaprWorkflow(DaprRegistrationHelper.RegisterAllEntities);

var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

The builder.Services.AddDaprWorkflowClient(); statement is required for typical Dapr Workflow client registration and is not impacted by this attribute, but is included for completeness. However, the following line builder.Services.AddDaprWorkflow(DaprRegistrationHelper.RegisterAllEntities); will not work until the aspect has been applied to your project as neither the DaprRegistrationHelper static class nor its internal method will necessarily already exist in your project. Rather, these will be introduced by the fabric and aspect and are invoked precisely as you see above as though you'd written them yourself. And that's it!

Happy coding!

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.10.29.1 70 10/29/2024
2024.10.15.1 81 10/15/2024
2024.10.2.2 90 10/2/2024
2024.10.2.1 82 10/2/2024
2024.9.27.7 89 9/27/2024
2024.9.27.5 85 9/27/2024