Building A Minimal IOC Container

I recently published a new library that is an extremely minimal dependency injection library: TiDI. It has an intentionally small feature set and is designed specifically for class-based dependency injection

Below is a simple example showing how to use TiDI (pronounced “tie dye”):

import { Container, inject, injectable } from "tidi"

@injectable("userService")
class LoggingService {}

@injectable("userService")
class UserService {
  @inject("loggingService") private loggingService: LoggingService
}

const container = new Container()
container.bind(LoggingService, UserService)
container.get<UserService>("userService")

It also supports constructor injection which is useful when you need to access injected services in the constructor.

@injectable("userService")
class UserService {
  constructor(
    @inject("loggingService") private loggingService: LoggingService,
  ) {
    this.loggingService.log("In the constructor!")
  }
}

Let me know if you find TiDI useful!