Compze.DependencyInjection 0.8.0-alpha

This is a prerelease version of Compze.DependencyInjection.
dotnet add package Compze.DependencyInjection --version 0.8.0-alpha
                    
NuGet\Install-Package Compze.DependencyInjection -Version 0.8.0-alpha
                    
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="Compze.DependencyInjection" Version="0.8.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Compze.DependencyInjection" Version="0.8.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Compze.DependencyInjection" />
                    
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 Compze.DependencyInjection --version 0.8.0-alpha
                    
#r "nuget: Compze.DependencyInjection, 0.8.0-alpha"
                    
#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 Compze.DependencyInjection@0.8.0-alpha
                    
#: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=Compze.DependencyInjection&version=0.8.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Compze.DependencyInjection&version=0.8.0-alpha&prerelease
                    
Install as a Cake Tool

Compze.DependencyInjection

Pluggable dependency injection abstractions for Compze.

What is Compze?

Compze is a .NET framework for building expressive domains through Teventive programming and Typermedia APIs. Learn more

What's in this package?

A container-agnostic dependency injection abstraction with a fluent registration API, lifestyle validation, scoped service resolution, and transactional scope execution.

Registration API

// Singleton with dependency injection
Singleton.For<IUserRepository>()
    .CreatedBy<IDbConnectionFactory>(factory => new UserRepository(factory));

// Scoped with multiple dependencies
Scoped.For<IOrderService>()
    .CreatedBy<IUserRepository, IEventBus>((repo, bus) => new OrderService(repo, bus));

// Pre-created singleton instance
Singleton.For<IConfiguration>()
    .Instance(myConfig);

Every chain ends with its instantiation spec — CreatedBy(...) or Instance(...). All modifiers (AllowSingletonDependent(), WithServiceResolver(), WithAssociatedRegistrations(), ...) come before it, and the terminal call returns a finished, immutable registration.

Breaking a circular dependency

When two components need each other, neither can be constructed first. Expose one side through an IServiceResolver<TService> with .WithServiceResolver(), and have the other side depend on that resolver instead of the service — it is constructed immediately holding only the resolver, and resolves the real service later, on demand:

Singleton.For<IServiceA>()
    .CreatedBy<ServiceA, IServiceResolver<IServiceB>>(serviceB => new ServiceA(serviceB));

Singleton.For<IServiceB>()
    .WithServiceResolver()
    .CreatedBy<ServiceB, IServiceA>(serviceA => new ServiceB(serviceA));

// class ServiceA(IServiceResolver<IServiceB> serviceB) : IServiceA
// {
//    // Resolve AFTER construction, never in the constructor — that would re-form the cycle.
//    public void DoWork() => serviceB.Resolve().Handle(this);
// }

A resolver is exposed for each service type the component is registered under (so a component registered as For<IServiceB, IServiceB2>() is resolvable through both IServiceResolver<IServiceB> and IServiceResolver<IServiceB2>). Each is registered at the target's own Lifestyle and carries the target's AllowSingletonDependent()/AllowScopedDependent() opt-ins, so a dependency on IServiceResolver<TService> is subject to exactly the same lifestyle validation as a direct dependency: a Singleton still may not take an IServiceResolver<TScoped>.

WithServiceResolver() is not a core special case — it is an ordinary extension built on WithAssociatedRegistrations(), the general mechanism by which a registration spec can attach extra registrations that are added to the container alongside it. Consumers can write their own such helpers the same way.

Core abstractions

  • IComponentRegistrar — Register components with lifestyle and factory methods
  • IContainerBuilder — Registrar plus Build(); the configure phase
  • IDependencyInjectionContainer — The built container: composes IRootResolver, IScopeFactory, and cloning
  • IRootResolver — Root-level resolution (singletons, transients)
  • IScopeFactory / IScope / IScopeResolver — Create scopes, own their lifetime, resolve within them
  • IUnitOfWorkResolver — An IScopeResolver whose scope is paired with an ambient transaction: a unit of work. Never container-resolvable — only ExecuteUnitOfWork (or UnitOfWorkResolver.From, which asserts the transaction) grants the typing. Also the unit of work's handle: Id (a value-equal UnitOfWorkId) plus the completion hooks OnCommittedSuccessfully/OnCompleted
  • IServiceResolver<TService> — Typed, deferred resolver for a single service; the supported way to break a constructor-injection cycle
  • LifestyleSingleton, Scoped, or TrackedTransient

Safety features

  • Lifestyle validation — Rejects captive dependencies at Build(): a Singleton may not depend on a Scoped component, and depending on a TrackedTransient from a Singleton or Scoped component requires the transient's explicit AllowSingletonDependent()/AllowScopedDependent() opt-in
  • Duplicate detection — Catches double-registered service types
  • Container cloning — Create isolated container copies for testing

Executing a unit of work

One scope and one transaction, begun and completed together — the work commits or rolls back as a whole:

container.ExecuteUnitOfWork(unitOfWork =>
{
    var repo = unitOfWork.Resolve<IUserRepository>();
    repo.Save(user);
}); // Scope disposed, transaction committed

// The deliberately-not-a-unit-of-work sibling, for work that changes nothing (a query, say):
container.ExecuteInIsolatedScope(scope => scope.Resolve<IUserReader>().Find(userId));

Installation

dotnet add package Compze.DependencyInjection
Package Description
Compze.DependencyInjection.Microsoft Microsoft DI integration
Compze.DependencyInjection.Autofac Autofac integration
Compze.DependencyInjection.DryIoc DryIoc integration
Compze.DependencyInjection.LightInject LightInject integration
Compze.Utilities Core utilities

License

Apache-2.0

Product Compatible and additional computed target framework versions.
.NET 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.

NuGet packages (19)

Showing the top 5 NuGet packages that depend on Compze.DependencyInjection:

Package Downloads
Compze.Abstractions

Core abstractions for the Compze framework: entity IDs, message type contracts, time sources, serialization interfaces, and type mapping infrastructure.

Compze.Tessaging

Messaging infrastructure for the Compze framework including command, query, and event handling.

Compze.Sql.Common

For Compze internal use only. Do not take a direct dependency on this package

Compze.Teventive

The Teventive programming model for the Compze framework: taggregates, tevents and tevent dispatching.

Compze.Tessaging.Hosting.Testing

Testing support for Compze Tessaging hosting: the Tessaging testing feature for the testing endpoint host, and the Tessaging transport and persistence test wiring.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.0-alpha 261 7/24/2026
0.7.0-alpha 214 7/15/2026
0.6.0-alpha 99 7/12/2026
0.5.0-alpha 79 7/11/2026
0.4.2-alpha 83 7/11/2026
0.4.1-alpha 70 7/10/2026
0.4.0-alpha 119 7/10/2026
0.3.0-alpha 544 6/4/2026