Mediator class
An implementation for the architectural mediator pattern, with CQRS support.
Future<void> main() async {
// Create a new mediator, this should only be needed once per your application.
Mediator mediator = Mediator();
// Register the command handler for its command type.
// This will hopefully be code-generated later on.
mediator.registerCommand(GetAsStringCommandHandler());
// Create and run your command.
String result = await mediator.runCommand(GetAsStringCommand(123));
print(result);
}
Constructors
- Mediator()
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
-
associateBaseEvent<
TSuper extends TBase, TBase extends IEvent> () → void - Associates a specific Type with it's base Type.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
raise<
TEvent extends IEvent> (TEvent event) → Future< void> -
Raises the given
event. -
registerCommand<
TCommand extends ICommand< (TResult> , TResult>ICommandHandler< TCommand, TResult> handler) → void - Registers an ICommandHandler for a custom ICommand type.
-
registerQuery<
TQuery extends IQuery< (TResult> , TResult>IQueryHandler< TQuery, TResult> handler) → void - Registers an IQueryHandler for a custom IQuery type.
-
runCommand<
TCommand extends ICommand< (TResult> , TResult>TCommand command) → Future< TResult> -
Executes the given
commandif a handler for it could be found, otherwise throws the StateError. -
runQuery<
TQuery extends IQuery< (TResult> , TResult>TQuery query) → Future< TResult> -
Executes the given
queryif a handler for it could be found, otherwise throws the StateError. -
subscribe<
TEvent extends IEvent> (EventFuction< TEvent> callback) → EventSubscription -
Subscribes a
callbackto be executed when theTEventis raised. -
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribe(
EventSubscription subscription) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited