Skip to content

NeoSyringeCompile-Time DI

Zero-overhead dependency injection that shifts resolution from Runtime to Build-Time. No reflection, no decorators, just pure TypeScript.

NeoSyringe

Why Choose NeoSyringe?

Traditional DI containers like InversifyJS and tsyringe rely on runtime resolution:

  • ❌ Ship DI container logic to the browser
  • ❌ Errors happen at runtime
  • ❌ Interfaces are erased, requiring manual Symbols
  • ❌ Need decorators and reflect-metadata

NeoSyringe is different. It works as a compiler plugin:

  • ✅ Generate optimized factories at build time
  • ✅ Errors detected in your IDE
  • ✅ Automatic interface IDs
  • ✅ Pure TypeScript, no decorators

Quick Example

typescript
// Pure TypeScript - no decorators!
interface ILogger {
  log(msg: string): void;
}

class ConsoleLogger implements ILogger {
  log(msg: string) { console.log(msg); }
}

class UserService {
  constructor(private logger: ILogger) {}
}

// Configure the container
import { defineBuilderConfig, useInterface } from '@djodjonx/neosyringe';

export const container = defineBuilderConfig({
  name: 'AppContainer',
  injections: [
    { token: useInterface<ILogger>(), provider: ConsoleLogger },
    { token: UserService }
  ]
});

// Use it with full type safety
const userService = container.resolve(UserService);
// Type: UserService ✅ - Full auto-completion!

Generated Output

The build plugin transforms your configuration into optimized code:

typescript
// Generated at build time
function create_ILogger() {
  return new ConsoleLogger();
}

function create_UserService(container) {
  return new UserService(container.resolve("ILogger"));
}

class NeoContainer {
  resolve<T>(token: any): T {  // ✨ Fully typed!
    if (token === "ILogger") return this.getInstance("ILogger", create_ILogger);
    if (token === UserService) return this.getInstance(UserService, create_UserService);
    throw new Error(`Service not found: ${token}`);
  }
}

export const container = new NeoContainer();

Zero DI library shipped to production!

Released under the MIT License.