OutWit.Communication.Client.DependencyInjection 2.3.5

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

OutWit.Communication.Client.DependencyInjection

Microsoft.Extensions.DependencyInjection integration for WitRPC client, providing easy registration and lifecycle management of WitRPC client services.

Overview

OutWit.Communication.Client.DependencyInjection provides seamless integration between WitRPC clients and the Microsoft Dependency Injection container. It allows you to register WitRPC clients as named services, manage their lifecycle through hosted services, and inject service proxies directly into your application components.

Key features:

  • Named client registration - Register multiple WitRPC clients with different configurations
  • Typed service registration - Inject service interfaces directly into your classes
  • Service resolution from DI - Access IServiceProvider during configuration to resolve loggers, tokens, etc.
  • Auto-connect support - Automatically connect clients when the application starts
  • Factory pattern - Use IWitClientFactory to create and manage clients dynamically

Installation

Install-Package OutWit.Communication.Client.DependencyInjection

Usage

Basic Registration

Register a WitRPC client with a name:

services.AddWitRpcClient("my-service", ctx =>
{
    ctx.WithWebSocket("ws://localhost:5000");
    ctx.WithJson();
    ctx.WithEncryption();
    ctx.WithAccessToken("your-token");
});
Typed Service Registration

Register a client and automatically create a service proxy:

services.AddWitRpcClient<IMyService>("my-service", ctx =>
{
    ctx.WithNamedPipe("MyServicePipe");
    ctx.WithJson();
    ctx.WithEncryption();
});

// Now you can inject IMyService directly
public class MyController
{
    private readonly IMyService _service;
    
    public MyController(IMyService service)
    {
        _service = service;
    }
}
Auto-Connect on Startup

Enable automatic connection when the application starts:

services.AddWitRpcClient("my-service", ctx =>
{
    ctx.WithTcp("127.0.0.1", 5000);
    ctx.WithJson();
    ctx.WithAutoReconnect(); // Enable auto-reconnect
}, autoConnect: true, connectionTimeout: TimeSpan.FromSeconds(30));

The autoConnect parameter registers an IHostedService that connects the client during application startup. You can also combine typed registration with auto-connect:

services.AddWitRpcClient<IMyService>("my-service", ctx =>
{
    ctx.WithWebSocket("ws://localhost:5000");
    ctx.WithJson();
    ctx.WithEncryption();
}, autoConnect: true, connectionTimeout: TimeSpan.FromSeconds(10));
Using the Factory

For more control, use IWitClientFactory:

public class MyService
{
    private readonly IWitClientFactory _factory;
    
    public MyService(IWitClientFactory factory)
    {
        _factory = factory;
    }
    
    public async Task DoWork()
    {
        var client = _factory.GetClient("my-service");
        await client.ConnectAsync(TimeSpan.FromSeconds(5), CancellationToken.None);
        
        var service = _factory.GetService<IMyService>("my-service");
        var result = await service.GetDataAsync();
    }
}
Multiple Clients

Register multiple clients with different configurations:

services.AddWitRpcClient("service-a", ctx =>
{
    ctx.WithWebSocket("ws://server-a:5000");
    ctx.WithJson();
});

services.AddWitRpcClient("service-b", ctx =>
{
    ctx.WithTcp("server-b", 6000);
    ctx.WithMessagePack();
});

services.AddWitRpcClient("service-c", ctx =>
{
    ctx.WithNamedPipe("MyLocalPipe");
    ctx.WithProtoBuf();
});
With Service Provider Access

Access the service provider during configuration to resolve dependencies like loggers, token providers, or configuration:

services.AddWitRpcClient("my-service", ctx =>
{
    var config = ctx.ServiceProvider.GetRequiredService<IConfiguration>();
    
    ctx.WithWebSocket(config["WitRpc:Url"]!);
    ctx.WithJson();
    ctx.WithEncryption();
    ctx.WithLogger<ILogger<MyApp>>();
    ctx.WithAccessTokenProvider<IMyTokenProvider>();
});

The WitClientBuilderContext inherits from WitClientBuilderOptions and adds IServiceProvider (via ctx.ServiceProvider), so all standard builder extension methods (e.g. WithJson, WithNamedPipe, WithTcp) work directly on the context. Additional extension methods can resolve services without explicitly passing the service provider:

Method Resolves
ctx.WithLogger<T>() Logger instance (e.g. ILogger<MyApp>)
ctx.WithLogger(categoryName) Logger via ILoggerFactory
ctx.WithAccessTokenProvider<T>() IAccessTokenProvider implementation
ctx.WithEncryptor<T>() IEncryptorClient implementation

This also works with typed registration and auto-connect:

services.AddWitRpcClient<IMyService>("my-service", ctx =>
{
    ctx.WithTcp("127.0.0.1", 5000);
    ctx.WithJson();
    ctx.WithLogger<ILogger<MyApp>>();
}, autoConnect: true, connectionTimeout: TimeSpan.FromSeconds(30));

Further Documentation

For more about WitRPC and dependency injection patterns, see the official documentation on witrpc.io.

License

Licensed under the Apache License, Version 2.0. See LICENSE.

Attribution (optional)

If you use OutWit.Communication.Client.DependencyInjection in a product, a mention is appreciated (but not required), for example: "Powered by WitRPC (https://witrpc.io/)".

Trademark / Project name

"WitRPC" and the WitRPC logo are used to identify the official project by Dmitry Ratner.

You may:

  • refer to the project name in a factual way (e.g., "built with WitRPC");
  • use the name to indicate compatibility (e.g., "WitRPC-compatible").

You may not:

  • use "WitRPC" as the name of a fork or a derived product in a way that implies it is the official project;
  • use the WitRPC logo to promote forks or derived products without permission.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OutWit.Communication.Client.DependencyInjection:

Package Downloads
OutWit.Communication.Client.HealthChecks

Health checks integration for WitRPC client, providing ASP.NET Core health checks for monitoring WitRPC client connectivity.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.5 96 2/6/2026
2.3.4 99 2/6/2026
2.3.3 98 2/6/2026
2.3.2 124 2/6/2026
2.3.1 121 1/25/2026
2.3.0 474 12/9/2025