LogoLogo
GitHub
  • Elsa Workflows 3
  • Getting Started
    • Concepts
    • Hello World
    • Prerequisites
    • Packages
    • Containers
      • Docker
      • Docker Compose
        • Elsa Server + Studio
        • Elsa Server + Studio - Single Image
        • Persistent Database
        • Traefik
  • Application Types
    • Elsa Server
    • Elsa Studio
    • Elsa Server + Studio (WASM)
  • Guides
    • HTTP Workflows
      • Programmatic
      • Designer
    • External Application Interaction
    • Loading Workflows from JSON
    • Running Workflows
      • Using Elsa Studio
      • Using a Trigger
      • Dispatch Workflow Activity
  • Activities
    • Control Flow
      • Decision
    • MassTransit
      • Tutorial
  • Expressions
    • C#
    • JavaScript
    • Python
    • Liquid
  • Extensibility
    • Custom Activities
  • Reusable Triggers (3.5-preview)
  • Multitenancy
    • Introduction
    • Setup
  • Operate
    • Variables
    • Activation Strategies
    • Incidents
      • Strategies
      • Configuration
    • Alterations
      • Alteration Plans
        • REST API
      • Applying Alterations
        • REST API
        • Extensibility
  • Optimize
    • Log Persistence
    • Retention
  • Hosting
    • Distributed Hosting
Powered by GitBook
On this page
  1. Operate
  2. Alterations
  3. Applying Alterations

Extensibility

Elsa Workflows supports custom alteration types, allowing developers to define their own types and utilize them as alterations.

To define a custom alteration type, implement the IAlteration interface.

public interface IAlteration
{
}

Next, implement an alteration handler that handles the alteration type.

public interface IAlterationHandler
{
    bool CanHandle(IAlteration alteration);
    ValueTask HandleAsync(AlterationContext context);
}

Or, derive from the AlterationHandlerBase<T> base class to simplify the implementation.

Finally, register the alteration handler with the service collection.

services.AddElsa(elsa => 
{
    elsa.UseAlterations(alterations => 
    {
        alterations.AddAlteration<MyAlteration, MyAlterationHandler>();
    })
});

Example

The following example demonstrates how to define a custom alteration type and handler.

public class MyAlteration : IAlteration
{
    public string Message { get; set; }
}

public class MyAlterationHandler : AlterationHandlerBase<MyAlteration>
{
    public override async ValueTask HandleAsync(AlterationContext context, MyAlteration alteration)
    {
        context.WorkflowExecutionContext.Output.Add("Message", context.Alteration.Message);
    }
}
PreviousREST APINextLog Persistence

Last updated 3 months ago