-
-
Save geggleto/f072939ba9adb2ea938caacb23919570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
Command, | |
CommandBus, | |
CommandHandlerMiddleware, | |
ClassNameExtractor, | |
InMemoryLocator, | |
HandleInflector, | |
LoggerMiddleware | |
} = require('simple-command-bus'); | |
// CreateAccount Command | |
class CreateAccountCommand extends Command { | |
constructor(firstName, lastName) { | |
super(); | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
} | |
// CreateAccount Handler | |
class CreateAccountHandler { | |
handle(command) { | |
// Logic to create an account. | |
} | |
}; | |
// Handler middleware | |
var commandHandlerMiddleware = new CommandHandlerMiddleware( | |
new ClassNameExtractor(), | |
new InMemoryLocator({ CreateAccountHandler: new CreateAccountHandler() }), | |
new HandleInflector() | |
); | |
// Command bus instance | |
var commandBus = new CommandBus([ | |
new LoggerMiddleware(console), | |
commandHandlerMiddleware | |
]); | |
const createAccountCommand = new CreateAccountCommand('John', 'Doe'); | |
var result = commandBus.handle(createAccountCommand); | |
console.log('Result:', result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment