TechTeaStudio.Injector 0.2.0

dotnet add package TechTeaStudio.Injector --version 0.2.0
                    
NuGet\Install-Package TechTeaStudio.Injector -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TechTeaStudio.Injector" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TechTeaStudio.Injector" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TechTeaStudio.Injector" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TechTeaStudio.Injector --version 0.2.0
                    
#r "nuget: TechTeaStudio.Injector, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TechTeaStudio.Injector@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TechTeaStudio.Injector&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=TechTeaStudio.Injector&version=0.2.0
                    
Install as a Cake Tool

TechTeaStudio.Injector

A lightweight, expression-tree-compiled dependency injection container for .NET 8 / 9 / 10. Built from scratch with no dependency on Microsoft.Extensions.DependencyInjection in the core library. A dedicated sidecar package (TechTeaStudio.Injector.Extensions.DependencyInjection) plugs it into ASP.NET Core / Generic Host / EF Core when you need them.

What's in v0.2.0 + v0.3.0

Core library (TechTeaStudio.Injector)

  • Fluent registration: builder.Register<IFoo, Foo>().AsSingleton();
  • Three lifetimes: transient, scoped, singleton.
  • Constructor / property / method injection (the latter two via [Inject]).
  • Open generics: builder.Register(typeof(IRepo<>), typeof(Repo<>)).AsScoped(). Closed generics synthesized on demand.
  • Lazy<T> / Func<T> / Func<P, T> auto-resolution. No registration needed.
  • Owned<T> ownership transfer (Autofac-style).
  • Decorators with compiled activators, composed in registration order.
  • Modules: bundle related registrations behind an IModule.
  • Assembly scanning: RegisterAssembly(asm, filter) for convention-based bulk wiring.
  • Collection resolution: ResolveAll<T>() returns IEnumerable<T>; ResolveDictionary<TKey, T>() returns keyed services.
  • OnActivating / OnActivated lifecycle hooks.
  • Child scopes with extra registrations: scope.BeginLifetimeScope(b => …).
  • Validate-on-build: builder.Build(new BuildOptions { ValidateOnBuild = true }).
  • IAsyncDisposable on IContainer and IScope.
  • Circular dependency detection with the full chain in CircularDependencyException.
  • Expression-tree compiled activators cached per (serviceType, lifetime).

Sidecar package (TechTeaStudio.Injector.Extensions.DependencyInjection)

  • Implements IServiceProvider, IServiceScope, IServiceScopeFactory, IServiceProviderIsService, IServiceProviderIsKeyedService, IKeyedServiceProvider.
  • IServiceProviderFactory<IContainerBuilder> for hostBuilder.UseServiceProviderFactory(new InjectorServiceProviderFactory()).
  • PopulateFromServiceCollection round-trips every ServiceDescriptor shape (all 12 variants including the keyed mirrors).

Build & test

dotnet build Injector.slnx
dotnet test  Injector.slnx

Requires .NET SDK 10. The core library multi-targets net8.0;net9.0;net10.0; the sidecar does the same. The sample and the test projects are net10.0 only.

127 tests pass across the two test projects (82 core + 45 sidecar).

Quick start (core)

using TechTeaStudio.Injector;

var builder = new ContainerBuilder();

builder.Register<ILogger, ConsoleLogger>().AsSingleton();
builder.Register<IGreeter, Greeter>().AsTransient();
builder.RegisterDecorator<IGreeter, TimingGreeterDecorator>();

// Open generics:
builder.Register(typeof(IRepository<>), typeof(Repository<>)).AsScoped();

// Lifecycle hooks:
builder.Register<IDbInit, DbInit>()
       .AsSingleton()
       .OnActivated(_ => Console.WriteLine("DbInit constructed"));

await using IContainer container = builder.Build(new BuildOptions { ValidateOnBuild = true });

var greeter = container.Resolve<IGreeter>();
greeter.Greet("World");

await using (IScope scope = container.CreateScope())
{
    var repo = scope.Resolve<IRepository<User>>(); // closed-on-demand
    var lazy = scope.Resolve<Lazy<IGreeter>>();    // auto-wrapped

    using (Owned<IReportBuilder> owned = scope.Resolve<Owned<IReportBuilder>>())
    {
        owned.Value.Build();
    } // releases the owned graph
}

Quick start (ASP.NET Core / Generic Host)

using Microsoft.Extensions.Hosting;
using TechTeaStudio.Injector;
using TechTeaStudio.Injector.Extensions.DependencyInjection;

var host = Host.CreateApplicationBuilder(args);

host.Services.AddSingleton<ILogger, ConsoleLogger>(); // standard IServiceCollection still works

host.ConfigureContainer(
    new InjectorServiceProviderFactory(),
    builder =>
    {
        builder.Register(typeof(IRepository<>), typeof(Repository<>)).AsScoped();
        builder.RegisterDecorator<IGreeter, TimingGreeterDecorator>();
    });

using var app = host.Build();
// All ASP.NET Core / EF Core / Hosting now resolves through TechTeaStudio.Injector under the hood.

Lifetimes at a glance

Lifetime Per-resolution behaviour When to use
AsTransient() New instance every call. Default for cheap, stateless services.
AsScoped() Same instance within a single IScope. Per-request / per-operation state.
AsSingleton() Single instance for the whole container's lifetime. Caches, configuration, expensive shared deps.

Release flow

CI builds and tests on every push / PR to the product branch. The two NuGet packages are published from product:

  • TechTeaStudio.Injector (core)
  • TechTeaStudio.Injector.Extensions.DependencyInjection (sidecar)

Comparison with Autofac and Microsoft.Extensions.DependencyInjection

Capability Injector Autofac MEDI
Constructor injection yes yes yes
Property / method injection yes ([Inject]) yes (PropertiesAutowired) no
Decorators (built-in) yes (compiled) yes no (Scrutor needed)
Modules / assembly scan yes yes no (Scrutor needed)
Open generics yes yes yes
Lazy<T> / Func<T> / Func<P, T> yes (auto) yes no
Owned<T> yes yes no
Lifecycle hooks (OnActivating / OnActivated) yes yes no
Child scopes with extra registrations yes yes no
IEnumerable<T> / IReadOnlyDictionary<TKey,T> yes yes partial (IEnumerable<T> only)
Validate-on-build yes (opt-in) partial yes
IAsyncDisposable yes yes yes
Circular detection with full chain yes partial partial
ASP.NET Core / Hosting integration via sidecar via Autofac.Extensions.DependencyInjection native
Keyed services (.NET 8 [FromKeyedServices]) yes (via sidecar) yes yes
NativeAOT not yet (v1.0 roadmap) partial yes

Picking Injector makes sense when you want Autofac's feature set without Autofac's surface area or 15 years of historical baggage, or when you want a from-scratch container with no transitive Microsoft.Extensions.* dependency in the core.

License

MIT. See LICENSE.txt.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TechTeaStudio.Injector:

Package Downloads
TechTeaStudio.Injector.Extensions.DependencyInjection

Microsoft.Extensions.DependencyInjection adapter for TechTeaStudio.Injector. Plugs the Injector container into ASP.NET Core / Generic Host / EF Core via IServiceProvider, IServiceScope, IServiceScopeFactory, IServiceProviderFactory<IContainerBuilder>, IServiceProviderIsService, IServiceProviderIsKeyedService, IKeyedServiceProvider, and an IServiceCollection import helper.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 104 5/15/2026

v0.2.0 — Major feature wave bringing Autofac-style feature parity to the core container.

Added:
 * Open generics: builder.Register(typeof(IRepo<>), typeof(Repo<>)) with on-demand closing.
 * Lazy<T> / Func<T> / Func<P, T> auto-resolution; no registration needed.
 * IAsyncDisposable on IContainer and IScope.
 * Validate-on-build: builder.Build(new BuildOptions { ValidateOnBuild = true }).
 * Owned<T> ownership transfer.
 * OnActivating / OnActivated lifecycle hooks.
 * Child scopes with extra registrations: scope.BeginLifetimeScope(b => ...).
 * Compiled decorator activators (Expression-tree, cached per registration).
 * Build-time decorator validation.

For ASP.NET Core / Generic Host integration use the TechTeaStudio.Injector.Extensions.DependencyInjection sidecar package.

Full changelog: https://github.com/TechTeaStudio/Injector/blob/product/CHANGELOG.md