Skip to content

Commit

Permalink
🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
divmgl committed Oct 26, 2023
1 parent 84b1070 commit 072fc75
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions packages/nwire/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@
`nwire` is a package that provides simplified dependency injection in Node.js.

```tsx
// entrypoint.js
import { Container } from "nwire"
import { Container, Injected } from "nwire"

const context = Container
.register("prisma", new PrismaClient())
.register("redis", new Redis())
.group("services", (container) =>
container
.singleton("users", UsersService)
.singleton("tasks", TasksService)
.singleton("billing", BillingService)
)
.context()

const myUser = await context.services.users.findOne("1234")
```
type MyTypedContext = {
banner: string
my: MyService
}

```tsx
// UsersService.ts
class UsersService extends Injected {
findOne(id) {
return this.context.prisma.users.findUniqueOrThrow({ where: { id } })
export class MyService extends Injected<MyTypedContext> {
helloWorld() {
return this.context.banner
}
}

const context = Container.register("banner", () => "Hello world!")
.instance("my", MyService)
.context()

console.log(context.my.helloWorld()) // => console output: "Hello world!"
```

## API
Expand Down

0 comments on commit 072fc75

Please sign in to comment.