fastify-papr-plugin
/
1.1.2
fastify-papr-plugin 1.1.2
Install from the command line:
Learn more about npm packages
$ npm install @flash-tecnologia/fastify-papr-plugin@1.1.2
Install via package.json:
"@flash-tecnologia/fastify-papr-plugin": "1.1.2"
About this version
A dependency injection plugin for fastify framework.
yarn add @flash-tecnologia/fastify-awilix-plugin awilix
Next, set up the plugin:
import { fastifyAwilixPlugin } from '@flash-tecnologia/fastify-awilix-plugin'
Next, set up the plugin:
declare module '@flash-tecnologia/fastify-awilix-plugin' {
interface Cradle {
dateService: Date
printDate: string
}
}
const dateService = () => new Date();
const printService = ({dateService: Date}) => dateService().toDateString()
fastify.register(fastifyAwilixPlugin.default, {
module: {
dateService: asFunction(dateService).singleton(),
printDate: asFunction(printService).singleton()
}})
server.get(
'/status',
async (request) => {
const cradle = request.diScope.cradle
return cradle.printDate
}
)