ZkLink.Extensions.DependencyInjection 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZkLink.Extensions.DependencyInjection --version 1.1.0
                    
NuGet\Install-Package ZkLink.Extensions.DependencyInjection -Version 1.1.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="ZkLink.Extensions.DependencyInjection" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZkLink.Extensions.DependencyInjection" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ZkLink.Extensions.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 ZkLink.Extensions.DependencyInjection --version 1.1.0
                    
#r "nuget: ZkLink.Extensions.DependencyInjection, 1.1.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 ZkLink.Extensions.DependencyInjection@1.1.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=ZkLink.Extensions.DependencyInjection&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ZkLink.Extensions.DependencyInjection&version=1.1.0
                    
Install as a Cake Tool

ZkLink.Extensions.DependencyInjection

Registers one host-owned ZooKeeper session with Microsoft.Extensions.DependencyInjection. The core ZkLink project has no Microsoft.Extensions dependency.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ZkLink;
using ZkLink.Extensions.DependencyInjection;

// Register ZkLink before hosted services that use it with sequential host startup.
services.AddZkLink(new ZooKeeperClientOptions
{
    ConnectionString = "zk.example:2281/app"
});
services.AddHostedService<CoordinationWorker>();

sealed class CoordinationWorker(IZooKeeperClientAccessor clients) : BackgroundService
{
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        ZooKeeperClient client = clients.Client;
        await client.SyncAsync("/", stoppingToken);
    }
}

Inject IZooKeeperClientAccessor into constructors. Read its Client after successful startup to obtain the current shared client. Disposing a child scope or the borrowed client view preserves the host session. Explicitly calling CloseAsync on that view closes the session for every consumer.

AddZkLink accepts an options object or a factory that receives the root IServiceProvider. The host invokes the factory during startup. An application that resolves ZooKeeperClientOptions as a service must register its own instance. Keep application-owned authentication objects and certificates alive until startup has captured them. A factory used for session replacement must supply valid credentials on each invocation.

Startup waits for connection readiness within InitialConnectTimeout and propagates connection failures. Register ZkLink before dependent services for sequential startup. Concurrent startup requires an application readiness barrier. During shutdown the accessor becomes unavailable, the host waits for any pending replacement to finish cleanup, and graceful shutdown requests acknowledged close.

The factory overload accepts a ZkLinkTerminalPolicy. The default Fail keeps the terminal client available for inspection. StopApplication requests graceful host shutdown. Recreate invokes the options factory again to start a new ZooKeeper session. Read the accessor again to obtain the replacement and rebuild watches, ephemerals and coordination state as appropriate. A failed replacement requests host shutdown. Ordinary disconnections use the core client’s same-session recovery.

Hosts using Microsoft health checks can add services.AddHealthChecks().AddCheck<ZkLinkHealthCheck>("zookeeper"). The check reads the current session state locally. Connected is healthy, connecting or recovering is degraded, and a terminal or unavailable session is unhealthy.

Calling AddZkLink twice in one service collection throws. Use an explicitly owned client for a separate security or coordination identity. The factory, terminal policies and health check are available in the development source following the 1.0.3 release.

Native AOT verification uses packed core and DI packages, a rooted analysis consumer and an unrooted native host. The host checks constructor injection, shared access across synchronous and asynchronous scopes, borrowed-client disposal, live operations, acknowledged shutdown and ephemeral cleanup. The native workflow runs these checks on Linux x64/arm64, Windows x64 and macOS arm64, against ZooKeeper 3.8.7 and 3.9.6 with TLS and mTLS. See the native verification guide for commands and evidence scope. This verifies the documented host integration; it does not establish compatibility for arbitrary application registrations or dependencies.

The public 1.0.2 packages passed this matrix in verification run 42410311495: all eight jobs passed, with 48 native DI lifecycle cases and no trim/AOT warnings.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 96 11/24/2026
1.2.0 143 11/20/2026
1.1.1 156 11/18/2026
1.1.0 95 11/18/2026
1.0.3 102 11/7/2026
1.0.2 105 11/7/2026
1.0.1 97 11/7/2026