For the complete documentation index, see llms.txt. This page is also available as Markdown.

How to Implement a Request Handler

How-to ยท Applies to Brighter V10

To implement a handler, derive from RequestHandler<T> where T should be the Command or Event derived type that you wish to handle. Then override the base class Handle() method to implement your handling for the Command or Event.

For example, assume that you want to handle the Command GreetingCommand

public class GreetingCommand : Command
{
    public GreetingCommand(string name)
        : base(Guid.NewGuid())
    {
        Name = name;
    }
    
    public string Name { get; private set; }
}

Then derive your handler from RequestHandler<GreetingCommand> and accept a parameter of that type on the overriden Handle() method.

public class GreetingCommandHandler : RequestHandler<GreetingCommand>
{
    public override GreetingCommand Handle(GreetingCommand command)
    {
        Console.WriteLine("Hello {0}", command.Name);
        return base.Handle(command);
    }
}

Last updated

Was this helpful?