purista
purista copied to clipboard
feat: add provides ressource to service builder
A service acts as container for commands and subscriptions. In real world, commands and subscriptions will need resources like database connections.
Instead of writing custom classes or to directly import connections, it might make sense, if the service builder gets a .provides
method.
The service builder:
serviceBuilder.provides<TypeOfRessource>('database', 'a short description for database ressource')
Command and subscription functions:
.setCommandFunction(async function ( { resources }, _payload, parameter) {
const { database } = resources
})
This also allows better testing, as the resources can be stubbed via the mock context.
const context = getCommandContextMock(payload, parameter, sandbox)
context.stubs. resources.database = sandbox.stub()
Also, later on, it can be used for documentation and visualization.