Invokable
If handler executes an action, but doesn't return any return value, then Avalanche.Void can used as return type.
/// <summary>Request to alarm</summary>
public struct AlarmRequest { }
/// <summary>Handle alarm request</summary>
public class AlarmHandler : IHandler<AlarmRequest, Avalanche.Void>
{
public void Handle(IQuery<AlarmRequest, Avalanche.Void> query)
{
// Alarm system
Console.WriteLine("ALARM!!!!");
// Assign void to indicate that request is handled
query.Response.SetValueVoid();
}
}
Service can be called with .Invoke() and .InvokeAsync() if return value is not needed.
// Create service
IService service = Services.Create(new AlarmHandler());
// Create request
AlarmRequest alarmRequest = new AlarmRequest();
// Issue alarm
service.TryInvoke(alarmRequest);