Compze.DependencyInjection
0.8.0-alpha
dotnet add package Compze.DependencyInjection --version 0.8.0-alpha
NuGet\Install-Package Compze.DependencyInjection -Version 0.8.0-alpha
<PackageReference Include="Compze.DependencyInjection" Version="0.8.0-alpha" />
<PackageVersion Include="Compze.DependencyInjection" Version="0.8.0-alpha" />
<PackageReference Include="Compze.DependencyInjection" />
paket add Compze.DependencyInjection --version 0.8.0-alpha
#r "nuget: Compze.DependencyInjection, 0.8.0-alpha"
#:package Compze.DependencyInjection@0.8.0-alpha
#addin nuget:?package=Compze.DependencyInjection&version=0.8.0-alpha&prerelease
#tool nuget:?package=Compze.DependencyInjection&version=0.8.0-alpha&prerelease
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 methodsIContainerBuilder— Registrar plusBuild(); the configure phaseIDependencyInjectionContainer— The built container: composesIRootResolver,IScopeFactory, and cloningIRootResolver— Root-level resolution (singletons, transients)IScopeFactory/IScope/IScopeResolver— Create scopes, own their lifetime, resolve within themIUnitOfWorkResolver— AnIScopeResolverwhose scope is paired with an ambient transaction: a unit of work. Never container-resolvable — onlyExecuteUnitOfWork(orUnitOfWorkResolver.From, which asserts the transaction) grants the typing. Also the unit of work's handle:Id(a value-equalUnitOfWorkId) plus the completion hooksOnCommittedSuccessfully/OnCompletedIServiceResolver<TService>— Typed, deferred resolver for a single service; the supported way to break a constructor-injection cycleLifestyle—Singleton,Scoped, orTrackedTransient
Safety features
- Lifestyle validation — Rejects captive dependencies at
Build(): aSingletonmay not depend on aScopedcomponent, and depending on aTrackedTransientfrom aSingletonorScopedcomponent requires the transient's explicitAllowSingletonDependent()/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
Related packages
| 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 | Versions 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. |
-
net10.0
- Compze.Contracts (>= 0.7.1)
- Compze.Internals.Logging (>= 0.4.1-alpha)
- Compze.Internals.SystemCE (>= 0.4.0-internal)
- Compze.Threading (>= 0.9.0-alpha)
- Compze.Underscore (>= 0.6.0-beta)
- Compze.Unit (>= 0.6.0-beta)
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 |