lato icon indicating copy to clipboard operation
lato copied to clipboard

A command should be registered only by one handler

Open chkoar opened this issue 1 year ago • 1 comments

In the context of CQRS, a command should typically be handled by only one command handler per bounded context/module. However, it seems that this is not the case in the current implementation. Is this intentional? Ideally I would expect to raise an error on the registration.

from lato import Application, ApplicationModule, Command


class C(Command): ...


app = Application(name="App")
module_a = ApplicationModule("Module A")
app.include_submodule(module_a)


@module_a.handler(C)
def handler_a1(cmd: C):
    print("module_a1")


@module_a.handler(C)
def handler_a2(cmd: C):
    print("module_a2")

Prints:

module_a1
module_a2

chkoar avatar Jan 20 '25 14:01 chkoar

Hi @chkoar, You are absolutely right. There should be only one command handler per module, I can fix this in a next release. Thanks for reporting.

pgorecki avatar Mar 03 '25 06:03 pgorecki