Skip to content
pubscout

dart_mediator

0.4.1, released 2 years ago by matthiware.be

Configurable Mediator implementation for requests, commands, queries, and events.

WASM-ready
$ flutter pub add dart_mediator
Source repository

What it does

Provides a mediator pattern implementation allowing you to send requests, commands, and queries, and publish events with multiple handlers. It supports pipeline behaviors, event observers, and custom configurations.

AI-written summary of version 0.4.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to decouple request senders from their handlers using CQRS principles
  • You need to implement cross-cutting concerns using request/command pipelines
  • You require event publishing with parallel handler execution and event observation

Skip it when

  • Your application is extremely small and simple where direct method calls are sufficient
  • You prefer built-in state management solutions for UI rendering

Strengths

  • Clean decoupling of requests, queries, commands, and events
  • Supports pipeline behaviors and event observers for logging or cross-cutting concerns
  • Configurable and lightweight with no complex dependencies

Weaknesses

  • Requires manual registration of handlers
  • Adds indirection which can make tracing call paths harder in small apps

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

Not documented

import 'package:dart_mediator/mediator.dart';

class MyEvent implements DomainEvent {}

Future<void> main() async {
  final mediator = Mediator.create();
  mediator.events.on<MyEvent>().subscribeFunction((event) => print('event received'));
  await mediator.events.dispatch(MyEvent());
}

Alternatives

Packages that do the same job and could replace dart_mediator.