checked-inject

A dependency injection library that verifies all dependencies are met at compile time.

class NameKey extends TypeKey<string>() { private _: any }
class IdKey extends TypeKey<number>() { private _: any }

class User {
name: string
id: number
constructor(name: string, id: number) {
this.name = name; this.id = id
}

static inject = Inject.construct(this, NameKey, IdKey)
}

class App {
user: User
constructor(user: User) {
this.user = user
}
}

const UserModule = Module(ct => ct
.provideInstance(NameKey, 'Alice')
.provideInstance(IdKey, 123)
)

const AppModule = Module(UserModule, ct => ct
.provide(App, { user: User }, ({ user }) => new App(user))
)

AppModule.inject({ app: App }, ({ app }) => {
console.log(`Welcome, ${app.user.name}`)
})

Dependencies are injected to/from a Container, and can be combined into Modules.

Index

Namespaces

Type Aliases

Functions

Dependencies - ComputedKey

Dependencies - InjectableClass

Dependencies - Other

Dependencies - TypeKey

Injection - Container

Injection - Module

Injection - Other

Scoping

Generated using TypeDoc