One Operation, One Handler

A common modern pattern is to implement each operation as a separate request handler class. Instead of one large BankService class with many methods, the system has one request handler class per operation. The following example shows four banking operations, each implemented by its own handler class:

BankMakeDepositHandler
BankWithdrawHandler
BankTransferHandler
BankSearchHandler

Why This Scales

Example

The following example shows how the Bank.MakeDeposit operation can be implemented as a separate handler class. The method name is declared as an attribute on the handler, which allows for automatic discovery and registration without hardcoding method names in a central registry. The example assumes that there are request and response types defined as MakeDepositRequest and MakeDepositResponse classes, and that the handler implements a common interface IRpcRequestHandler.

[RpcMethod("Bank.MakeDeposit", Description = "Deposits money into an existing bank account.", IsReadOnly = false)]
public class BankMakeDepositHandler : IRpcRequestHandler<MakeDepositRequest, MakeDepositResponse>
{
    public Task<MakeDepositResponse> HandleAsync(MakeDepositRequest request, CancellationToken cancellationToken)
    {
        ...
    }
}

Why This Pattern Appears Frequently

The idea of assigning one handler to one operation appears in many modern software systems. It helps keep business logic small, focused, and easier to test and maintain. Instead of placing many unrelated operations into large service classes, the system treats each request as an independent operation handled by its own dedicated component.

 

Table of Content Operation-Oriented APIs and AI Tools Previous: Dependency Injection Role Next: Automatic Discovery and Registration

 


Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness or suitability of the information and are not responsible for any damages resulting from its use.