Implementing services
Implementing a service is creating a function that returns the service.
To implement a service in Diabolo, you need to use the lazyCreateServiceImpl
function.
import * as DI from 'diabolo'
const myServiceImpl = DI.lazyCreateServiceImpl<MyService>(() => ({
myFunction: () => {
console.log('Hello, world!')
}
}))
If you need to use another service in your implementation, you can use the
createFunction
function.
import * as DI from 'diabolo'
const otherServiceImpl = DI.lazyCreateServiceImpl<OtherService>(() => ({
otherFunction: DI.createFunction(function* () {
const myService = yield * DI.requireService(myService)
yield * myService.myFunction()
})
}))