Skip to main content

Dependency Injection

💡 Don’t understand Dependency Injection (DI) or Inversion of Control (IoC)? Totally fine. You can skip this doc and Nubie will still love you.

Nubie gives you straightforward access to DI using tsyringe under the hood.

Registering Services​

NubieContainer.addSingleton("IAuthService", GithubAuthService);
// NubieContainer.addTransient("IAuthService", GithubAuthService);

/** Injection */
@ApiController()
class LoginController {
private readonly _authService: IAuthService;

constructor(@Inject("IAuthService") authService: IAuthService) {
this._authService = authService;
}
}

👆 That’s it. Nubie slides the right service into your class when it spins it up. No new, no fuss, just that crisp DI goodness.