Skip to content

Warning when Effect injects a IDispatcher #18

@mshimshon

Description

@mshimshon

Summary

Introduce a Roslyn analyzer that generates a compile time warning when a class implementing IEffect injects either IDispatcher.

Problem

IEffect handlers are executed inside an existing StatePulse pipeline chain.
This chain is responsible for:

  • propagation of cancellation
  • anti duplication safeguards
  • race condition protection
  • ordered dispatch execution

If an IEffect directly injects and uses a new IDispatcher, it creates a new dispatch chain instead of continuing the existing one.

This detaches the execution flow from the current pipeline.

As a result:

  • cancellation from the original pipeline are lost
  • anti duplication guarantees are bypassed
  • race condition protections are broken
  • dispatch ordering guarantees are no longer enforced

Why This Matters

If the parent pipeline is cancelled, any dispatch started through an injected IDispatcher will continue executing independently.

This leads to:

  • inconsistent state mutations
  • duplicate effects
  • race conditions between pipelines

Developers must be aware of this behavior at compile time.

Analyzer Behavior

Emit a warning diagnostic when:

A class:

  • implements IEffect

AND

  • injects IDispatcher

via constructor injection or field injection.

Example that should trigger the analyzer:

public class MyEffect : IEffect<MyAction>
{
    private readonly IDispatcher _dispatcher;

    public MyEffect(IDispatcher dispatcher)
    {
        _dispatcher = dispatcher;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions