Skip to content

FAQ

Can I have multiple application containers?

Yes, no problem at all. If you want, they can even share tokens and hence instances!

Why getItems is always async?

As of v0.8.0, ITI now supports synchronous item retrieval via getSync() and getItemsSync() methods! These are particularly useful for SSR scenarios.

The async getItems() method remains the primary API because:

  • It provides a consistent interface for both sync and async dependencies
  • Most real-world frontend dependencies are already async
  • It keeps TypeScript types simpler and more predictable

For synchronous access to cached items, use the new getSync() or getItemsSync() methods.

We strongly believe that helps to implement good DI patterns in your codebase and offers better tradeoffs compared to alternative DI frameworks or solutions. Check our alternatives section

You can not create a circular dependency with iti and typescript. It will throw a typescript error if you try :)

import { createContainer } from "iti"
/*
// Part 1: You can create a circular dependency
// in your business logic
┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
│ A │──▶│ B │──▶│ C │──▶│ D │──▶│ E │
└───┘ └───┘ └───┘ └───┘ └───┘
▲ │
│ │
└───────────────┘
*/
class A {
constructor() {}
}
class B {
constructor(a: A) {}
}
class C {
constructor(b: B, e: E) {}
}
class D {
constructor(c: C) {}
}
class E {
constructor(d: E) {}
}
// Part 2: You can't express a circular dependency because of typescript checks
createContainer()
.add((ctx) => ({
a: () => new A(),
}))
.add((ctx) => ({
b: () => new B(ctx.a),
}))
.add((ctx) => ({
// This line will throw a Typescript error at compile time
c: () => new C(ctx.a, ctx.e),
}))