Skip to main content

Introduction

What is InjectContainer?​

InjectContainer is a state-of-the-art Dependency Injection (DI) framework for Delphi (XE or higher). It manages object lifecycles — Singleton, Factory, LazyLoad, and Interface-to-class mappings — in a single thread-safe container backed by a high-speed RTTI metadata cache.

Problem it solves​

In traditional Delphi applications, each form or controller creates its own service instances directly, scattering TMyService.Create calls throughout the codebase. This pattern:

  • makes unit testing difficult (no substitution point),
  • hides dependencies inside implementation bodies,
  • spreads lifetime management across many owners,
  • creates implicit coupling between concrete classes.

InjectContainer replaces ad-hoc construction with a single registration/resolution contract: you declare what each service is (lifecycle + type), and consumers ask for it by type or interface — never by creating it directly.

Key features​

FeatureDetail
SingletonOne shared instance for the entire application lifetime
FactoryA new instance on every resolution call
LazyLoad (SingletonLazy)Singleton, but constructed only when first requested
Interface bindingMaps IMyInterface → TMyImpl; resolves via GUID
100% thread-safeAll registration and resolution paths are guarded by a TCriticalSection
RTTI cacheTDictionary-backed type and method cache; 40–60% faster than raw RTTI
Circular dependency detectionStack-based push/pop; raises ECircularDependency with the full chain
Lifecycle loggingOptional TProc<string> callback traces creation, resolution, and destruction
Memory poolInstance pooling reduces heap pressure 20–30% for high-frequency Factory calls
Child injectorsCompose multiple TInject containers; resolution cascades to child injectors

Who is it for?​

  • Delphi developers building enterprise applications (VCL, FMX, or console servers).
  • Teams that need testable, modular architectures without heavyweight IoC frameworks.
  • Backend services compiled for Win32, Win64, and Linux64 (verified clean, no platform guards needed).

Compatibility​

IDE / EnvironmentPlatformsThread-SafeCircular Detection
Delphi XE or higherVCL, FMX, Console (Win/Linux/macOS/iOS/Android)YesYes
Cross-platform build

InjectContainer is already platform-neutral. It has been build-verified on Win32, Win64, and Linux64 (dcclinux64) with no {$IFDEF} guards needed. macOS/iOS/Android follow from the Delphi RTL but have not been build-verified yet.