Implement to create a handler for your custom ICommand implementation.
// Create a new handler for your command, each command should get one, and only one handler.
// Multiple return types might be supported in the future.
class ConvertToStringCommandHandler
implements ICommandHandler<ConvertToStringCommand, String> {
@override
Future<String> handle(ConvertToStringCommand request) {
// Put your handler implementation here.
// Handlers are async by default to allow for future middleware support.
String result = request.number.toString();
return Future.value(result);
}
}
I recommend creating an extension method for your handler too, (this will hopefully be code-generated in the future):
extension ConvertToStringCommandMediator on Mediator {
Future<String> convertToString(int number) {
return runCommand(ConvertToStringCommand(number));
}
}
void main() async {
// Create a new mediator, this should only be needed once per your application.
Mediator mediator = Mediator();
// Register the query handler for its query type.
// This will hopefully be code-generated later on.
mediator.registerCommand(ConvertToStringQueryHandler());
// If you implemented the optional extension method, then you can do this instead.
String result = await mediator.convertToString(123);
print(result);
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
handle(
TCommand request) → Future< TResult> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited