Skip to content

What is Alloy?

Alloy is a Vite plugin for compile-time dependency injection.

It scans your code at build time to build a dependency graph and generates a DI container, which is then available to your application as a virtual module. This approach minimizes runtime overhead, avoids reflect-metadata, and provides a clean, declarative API for managing your services.

Why Alloy?

Traditional DI frameworks configure containers at runtime and often rely on reflect-metadata (which adds bloat and runtime cost) or require verbose manual registration.

Alloy shifts resolution to build time:

  • Zero Runtime Reflection: No metadata emission required.
  • Minimal Overhead: The container is just a map of factories generated by the bundler.
  • Explicit Lazy Loading: First-class support for code-splitting via Lazy().
  • Type Safe: Generates type definitions for service identifiers automatically.

High-Level Architecture

           Source Files (.ts, .tsx)

        Vite Transform (plugin)
                │  scans for @Injectable

    Discovered Class Metadata Map

          Virtual Module Loader
                │  generates code

  virtual:alloy-container (Container instance)

         Application Runtime
                │  async get()/lazy import resolution

           Service Instances