Skip to content

Commit 22bf3a9

Browse files
committed
first commit
0 parents  commit 22bf3a9

File tree

14 files changed

+13209
-0
lines changed

14 files changed

+13209
-0
lines changed

.github/workflows/publish.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish Package to npmjs
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
# Setup .npmrc file to publish to npm
11+
- uses: actions/setup-node@v3
12+
with:
13+
node-version: '16.x'
14+
registry-url: 'https://registry.npmjs.org'
15+
- run: npm ci
16+
- run: npm publish --access public
17+
env:
18+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
pnpm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
14+
# OS
15+
.DS_Store
16+
17+
# Tests
18+
/coverage
19+
/.nyc_output
20+
21+
# IDEs and editors
22+
/.idea
23+
.project
24+
.classpath
25+
.c9/
26+
*.launch
27+
.settings/
28+
*.sublime-workspace
29+
30+
# IDE - VSCode
31+
.vscode/*
32+
!.vscode/settings.json
33+
!.vscode/tasks.json
34+
!.vscode/launch.json
35+
!.vscode/extensions.json
36+
.history
37+
.yarn

BUILD_SHA

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HEAD

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# fastify-di-plugin
2+
3+
A dependency injection plugin for fastify framework, using [awilix](https://github.com/jeffijoe/awilix)
4+
5+
Motivation: I really wanted use [fastify-awilix](https://github.com/fastify/fastify-awilix) but this plugin make things statics. So, basically, this plugin can be used without problem with parallel tests and so on.
6+
7+
## Getting started
8+
9+
```bash
10+
yarn add @inaiat/fastify-di-plugin awilix
11+
```
12+
13+
Next, set up the plugin:
14+
```ts
15+
import { fastifyAwilixPlugin } from '@inaiat/fastify-di-plugin'
16+
```
17+
18+
Next, set up the plugin:
19+
```ts
20+
declare module '@inaiat/fastify-di-plugin' {
21+
interface Cradle {
22+
dateService: Date
23+
printDate: string
24+
}
25+
}
26+
27+
const dateService = () => new Date();
28+
const printService = ({dateService: Date}) => dateService().toDateString()
29+
30+
fastify.register(fastifyAwilixPlugin.default, {
31+
module: {
32+
dateService: asFunction(dateService).singleton(),
33+
printDate: asFunction(printService).singleton()
34+
}})
35+
36+
server.get(
37+
'/status',
38+
async (request) => {
39+
const cradle = request.diScope.cradle
40+
return cradle.printDate
41+
}
42+
)
43+

0 commit comments

Comments
 (0)