Rather than passing the fastify instance to every function, how can I pass it at a top level only once so its available to all functions in the controller?
// route file
import { FastifyPluginAsync } from 'fastify'
import RootController from '../root.controller'
const root: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
fastify.get('/', RootController.index(fastify))
fastify.get('/show', RootController.show(fastify))
}
export default root
// controller file
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'
export default {
index: (fastify: FastifyInstance) => async (request: FastifyRequest, reply: FastifyReply) => {
const hugs = fastify.someSupport()
reply.send({ status: 'ok', love: hugs })
},
show: (fastify: FastifyInstance) => async (request: FastifyRequest, reply: FastifyReply) => {
const hugs = 'extra ' + fastify.someSupport()
reply.send({ status: 'ok', love: hugs })
}
}