Overview
The dart_mediatr package implements the Mediator pattern in Dart, inspired by MediatR from ASP.NET Core. It centralizes command and query handling, promoting clean separation of concerns. The package supports dynamic handler registration through code generation, reducing boilerplate and improving maintainability. Ideal for organizing complex application logic in Flutter apps, it enables scalable and testable architectures by decoupling senders from handlers.
Use cases
- Handling business logic in Flutter apps
- Managing commands and queries in a centralized way
- Enabling clean separation of concerns in large-scale applications
- Simplifying event-driven architecture
- Supporting dependency injection with handlers
- Facilitating unit testing of business logic
Key features
- Code generation for dynamic handler registration
- Centralized command and query processing
- Support for asynchronous and synchronous handlers
- Integration with dependency injection
- Minimal boilerplate with generated code
- Cross-platform compatibility
Suitable for
- Large Flutter applications with complex workflows
- Teams seeking structured architecture patterns
- Developers using dependency injection
- Projects requiring testable and maintainable business logic
- Applications leveraging event-driven or CQRS-like patterns
Considerations
- Requires code generation setup
- Learning curve for new developers unfamiliar with Mediator pattern
- Potential overhead for very simple apps
- Dependency on build_runner for code generation
- Limited documentation compared to mature frameworks