![]() |
VOOZH | about |
dotnet add package Innovian.Dapr.Workflow.RegistrationAspect --version 2024.10.29.1
NuGet\Install-Package Innovian.Dapr.Workflow.RegistrationAspect -Version 2024.10.29.1
<PackageReference Include="Innovian.Dapr.Workflow.RegistrationAspect" Version="2024.10.29.1" />
<PackageVersion Include="Innovian.Dapr.Workflow.RegistrationAspect" Version="2024.10.29.1" />Directory.Packages.props
<PackageReference Include="Innovian.Dapr.Workflow.RegistrationAspect" />Project file
paket add Innovian.Dapr.Workflow.RegistrationAspect --version 2024.10.29.1
#r "nuget: Innovian.Dapr.Workflow.RegistrationAspect, 2024.10.29.1"
#:package Innovian.Dapr.Workflow.RegistrationAspect@2024.10.29.1
#addin nuget:?package=Innovian.Dapr.Workflow.RegistrationAspect&version=2024.10.29.1Install as a Cake Addin
#tool nuget:?package=Innovian.Dapr.Workflow.RegistrationAspect&version=2024.10.29.1Install as a Cake Tool
<a href="https://innovian.net"> <p align="center"> <img src="https://innovian.net/img/bluelogo.svg" width="100px"/> </p> </a>
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.
The attribute performs the following:
<Program namespace>.DaprUtilities where <Program namespace> is the namespace used in your Program.cs file within a public, partial, static class called DaprRegistrationHelper.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".
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.
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:
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2024.10.29.1 | 192 | 10/29/2024 |
| 2024.10.15.1 | 174 | 10/15/2024 |
| 2024.10.2.2 | 164 | 10/2/2024 |
| 2024.10.2.1 | 167 | 10/2/2024 |
| 2024.9.27.7 | 183 | 9/27/2024 |
| 2024.9.27.5 | 168 | 9/27/2024 |