2 min read
Dependency Injection and IceRPC for C#
Understand how IceRPC for C# provides support for Dependency Injection (DI).
DI as an optional feature
The first rule of DI is: don't introduce a dependency on DI.
IceRPC for C# takes this rule at heart by providing full support for DI while making this support completely optional.
The IceRPC C# API was designed to be both DI-friendly and DI container agnostic. Additionally, IceRPC provides support code to help you use IceRPC with Microsoft's DI container.
DI APIs
All the DI-related APIs provided by IceRPC are in the same namespace, IceRpc.Extensions.DependencyInjection
, but are implemented by several assemblies:
- IceRpc.dll provides abstractions such as
IDispatcherBuilder
andIInvokerBuilder
IceRpc.Deadline.dll and other interceptor/middleware assemblies provide extension methods forIDispatcherBuilder
andIInvokerBuilder
. These extension methods are DI container agnostic. - IceRpc.Extensions.DependencyInjection.dll provides support code for Microsoft's DI container. This includes various extension methods for IServiceCollection, such as
AddIceRpcServer
andAddIceRpcClientConnection
, and implementations forIDispatcherBuilder
andIInvokerBuilder
.