0.1.0 • Published 2 years ago

@inaiat/fastify-awilix-plugin v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

fastify-awilix-plugin

A dependency injection plugin for fastify framework.

Getting started

yarn add @inaiat/fastify-awilix-plugin awilix

Next, set up the plugin:

import { fastifyAwilixPlugin } from '@inaiat/fastify-awilix-plugin'

Next, set up the plugin:

declare module '@inaiat/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
      }
    )
    
0.1.0

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago