cmdr 1.0.1 copy "cmdr: ^1.0.1" to clipboard
cmdr: ^1.0.1 copied to clipboard

Dart package that provides a lightweight implementation of the Mediator pattern tailored for Command Query Responsibility Segregation (CQRS) applications.

example/cmdr_example.dart

import 'package:cmdr/cmdr.dart';

import 'usecase/user/command/create_user_command.dart';
import 'usecase/user/command/create_user_command_handler.dart';
import 'usecase/user/query/get_user_query.dart';
import 'usecase/user/query/get_user_query_handler.dart';

void main() async {
  // Create an instance of mediator
  var mediator = Mediator();

  // Register command and query handlers
  var commandHandler = CreateUserCommandHandler();
  var queryHandler = GetUserQueryHandler();

  mediator.registerHandler(CreateUserCommand, commandHandler);
  mediator.registerHandler(GetUserQuery, queryHandler);

  // Example case for command
  var createUserCommand = CreateUserCommand('john_doe', 'john@example.com');
  print('Sending create user command...');
  await mediator.send(createUserCommand);

  // Example case for query
  var getUserQuery = GetUserQuery('123456');
  print('\nSending get user query...');
  var user = await mediator.send(getUserQuery);
  print('User details:');
  print('User ID: ${user.userId}');
  print('Username: ${user.username}');
  print('Email: ${user.email}');
}
3
likes
150
points
53
downloads

Publisher

verified publisherildeberto.com

Weekly Downloads

Dart package that provides a lightweight implementation of the Mediator pattern tailored for Command Query Responsibility Segregation (CQRS) applications.

Homepage
Repository (GitHub)
View/report issues

Topics

#cqrs #mediator #mediatr #command #query

Documentation

API reference

License

MIT (license)

More

Packages that depend on cmdr