PublishΒΆ
Publish()
is an IHandler
extension method that is used for notification. It will traverse the context and execute every handler that can handle the message. If no handler is found, it will not throw and exception. Published messages do not return a response.
In this example we are executing Publish()
off of the IHandler composer
that is passed in to the [Mediates]
method. Mediator will find and execute all handlers that can handle TeamCreated.
namespace Example.Handler.WithComposer
{
using League.Api.Team;
using Miruken.Callback;
using Miruken.Mediate;
public class TeamHandler
{
[Mediates]
public TeamResult CreateTeam(CreateTeam request, IHandler composer)
{
var team = request.Team;
composer.Publish(new TeamCreated());
return new TeamResult
{
Team = team
};
}
}
}