Compze.DependencyInjection
0.4.0-alpha
See the version list below for details.
dotnet add package Compze.DependencyInjection --version 0.4.0-alpha
NuGet\Install-Package Compze.DependencyInjection -Version 0.4.0-alpha
<PackageReference Include="Compze.DependencyInjection" Version="0.4.0-alpha" />
<PackageVersion Include="Compze.DependencyInjection" Version="0.4.0-alpha" />
<PackageReference Include="Compze.DependencyInjection" />
paket add Compze.DependencyInjection --version 0.4.0-alpha
#r "nuget: Compze.DependencyInjection, 0.4.0-alpha"
#:package Compze.DependencyInjection@0.4.0-alpha
#addin nuget:?package=Compze.DependencyInjection&version=0.4.0-alpha&prerelease
#tool nuget:?package=Compze.DependencyInjection&version=0.4.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);
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>()
.CreatedBy<ServiceB, IServiceA>(serviceA => new ServiceB(serviceA))
.WithServiceResolver();
// 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, 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 can carry extra registrations
that are added to the container alongside it. Consumers can write their own such helpers the same way.
Core abstractions
IDependencyInjectionContainer— Container lifecycle, registration, andIServiceLocatoraccessIServiceLocator— Resolve services by type, create scoped locatorsIComponentRegistrar— Register components with lifestyle and factory methodsIServiceResolver<TService>— Typed, deferred resolver for a single service; the supported way to break a constructor-injection cycleLifestyle—SingletonorScoped
Safety features
- Lifestyle validation — Prevents singletons from depending on scoped components
- Duplicate detection — Catches double-registered service types
- Container cloning — Create isolated container copies for testing
Transactional scope execution
serviceLocator.ExecuteInIsolatedScope(locator =>
{
var repo = locator.Resolve<IUserRepository>();
repo.Save(user);
}); // Scope disposed, transaction committed
Installation
dotnet add package Compze.DependencyInjection
Related packages
| Package | Description |
|---|---|
| Compze.DependencyInjection.Microsoft | Microsoft DI integration |
| Compze.DependencyInjection.SimpleInjector | SimpleInjector 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.0)
- Compze.Internals.Logging (>= 0.4.0-alpha)
- Compze.Internals.SystemCE (>= 0.2.1-internal)
- Compze.Threading (>= 0.7.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.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. |
|
|
Compze.Teventive
The Teventive programming model for the Compze framework: taggregates, tevents and tevent dispatching. |
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 | 215 | 7/15/2026 |
| 0.6.0-alpha | 99 | 7/12/2026 |
| 0.5.0-alpha | 81 | 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 |