Skip to content
James Burlison edited this page Dec 5, 2025 · 5 revisions

SSDI - Super Simple Dependency Injection

Welcome to the SSDI wiki! SSDI is a lightweight, high-performance dependency injection container designed specifically for .NET games and console applications.

Why SSDI?

  • ⚡ Fast - Expression-compiled factories with near-zero allocation resolution
  • 🎮 Game-Friendly - No build step, dynamic registration, hot-swapping support
  • 🔧 Simple API - Fluent configuration, intuitive design
  • 📦 Lightweight - Minimal footprint, focused feature set
  • 🔒 Thread-Safe - Lock-free resolution path, safe for multi-threaded environments.

Quick Start

// Create container
var container = new DependencyInjectionContainer();

// Register services
container.Configure(c =>
{
    c.Export<GameEngine>().Lifestyle.Singleton();
    c.Export<PlayerService>().As<IPlayerService>();
    c.Export<Enemy>();  // Transient by default
});

// Resolve services
var engine = container.Locate<GameEngine>();
var playerService = container.Locate<IPlayerService>();

Installation

dotnet add package SSDI

Or via Package Manager:

Install-Package SSDI

Key Features

Feature Description
Lifetimes Singleton, Transient, and Scoped lifetime management
Registration Fluent API for type and interface registration
Parameter Injection Named, positional, and typed constructor parameters
Scopes Per-request/per-player scoped services
Unregistration & Events Hot-swap implementations at runtime

Documentation

Game Server Example

var container = new DependencyInjectionContainer() { EagerCompilation: true }; // EagerCompilation is optional.

container.Configure(c =>
{
    // App-lifetime services
    c.Export<GameEngine>().Lifestyle.Singleton();
    c.Export<NetworkManager>().Lifestyle.Singleton();

    // Per-player services
    c.Export<PlayerInventory>().As<IInventory>().Lifestyle.Scoped();
    c.Export<PlayerStats>().Lifestyle.Scoped();

    // Frequently created objects
    c.Export<Projectile>();
    c.Export<ParticleEffect>();
});

// When a player connects
using var playerScope = container.CreateScope();
var inventory = playerScope.Locate<IInventory>();
var stats = playerScope.Locate<PlayerStats>();

// Player-specific instances, automatically disposed when scope ends

Performance

SSDI achieves competitive performance with popular DI containers:

Operation .NET 8 .NET 10
Singleton Resolution 5.93 ns 3.45 ns
Transient Resolution 63.17 ns 58.42 ns
Complex Graph (lazy) 46.97 ns 41.28 ns
Complex Graph (eager) 22.47 ns 19.42 ns

EagerCompilation mode: Pre-compiles all factories during Configure() for near-parity resolution performance with MS.DI/Grace/DryIoc (~19ns vs ~16ns). Trade-off: slower registration (~10ms vs ~27μs for lazy mode).

See Performance for detailed benchmarks and lazy vs eager comparison.

License

SSDI is released under the MIT License.

Contributing

Contributions are welcome! Please visit the GitHub repository to report issues or submit pull requests.

Clone this wiki locally