Inject Me Timbers is a typescript module for quick and simple dependency injection. Download, import, and inject to your heart's content.
Requires typescript
and experimentalDecorators to work nicely.
Create components. Everything is a component. Components build the application, get injected, help other components, etc. Everything's a component. Use the @Component
decorator to mark them in your code.
@Component()
export class WeatherComponent {
private weather: string = 'unbelievably scurvy';
whatIsTheWeather(): string {
return this.weather;
}
}
To use one component within another, inject them via the constructor
!
@Component()
export class ShipComponent {
constructor(
private weatherComponent: WeatherComponent
) {}
shouldWeSail(): boolean {
return this.weatherComponent.whatIsTheWeather() !== 'unbelievably scurvy';
}
}
Now it is time to bundle everything up. Create a module. Modules wrap everything else into a single package. Simply use the @Module
decorator, and list all components:
@Module({
components: [
ShipComponent,
WeatherComponent
]
})
export class MyModule {}
(TIP: You should not need that, but you can access all components in the module using this.__components__
property of the module)
Absolutely not.
Run npm test
to run unit tests. Like 4 of them.
MIT