Table of Contents

Interface IDispatcherBuilder

Namespace
IceRpc.Extensions.DependencyInjection
Assembly
IceRpc.dll

Provides the mechanism to configure a dispatcher when using Dependency Injection (DI). Each request is dispatched in its own scope.

public interface IDispatcherBuilder
Extension Methods

Properties

ServiceProvider

Gets the service provider.

IServiceProvider ServiceProvider { get; }

Property Value

IServiceProvider

The IServiceProvider.

Methods

Map<TService>(string)

Registers a route with a path. If there is an existing route at the same path, it is replaced.

IDispatcherBuilder Map<TService>(string path) where TService : notnull

Parameters

path string

The path of this route. It must match exactly the path of the request. In particular, it must start with a /.

Returns

IDispatcherBuilder

This builder.

Type Parameters

TService

The type of the DI service that will handle the requests. The implementation of this service must implement IDispatcher.

Remarks

With Slice, it is common for TService to correspond to a generated I{name}Service interface. This generated interface does not extend IDispatcher.

Exceptions

FormatException

Thrown if path is not a valid path.

Mount<TService>(string)

Registers a route with a prefix. If there is an existing route at the same prefix, it is replaced.

IDispatcherBuilder Mount<TService>(string prefix) where TService : notnull

Parameters

prefix string

The prefix of this route. This prefix will be compared with the start of the path of the request.

Returns

IDispatcherBuilder

This builder.

Type Parameters

TService

The type of the DI service that will handle the requests. The implementation of this service must implement IDispatcher.

Remarks

With Slice, it is common for TService to correspond to a generated I{name}Service interface. This generated interface does not extend IDispatcher.

Exceptions

FormatException

Thrown if prefix is not a valid path.

Route(string, Action<IDispatcherBuilder>)

Creates a sub-router, configures this sub-router and mounts it at the given prefix.

void Route(string prefix, Action<IDispatcherBuilder> configure)

Parameters

prefix string

The prefix of the route to the sub-router.

configure Action<IDispatcherBuilder>

A delegate that configures the new sub-router.

Use(Func<IDispatcher, IDispatcher>)

Registers a middleware.

IDispatcherBuilder Use(Func<IDispatcher, IDispatcher> middleware)

Parameters

middleware Func<IDispatcher, IDispatcher>

The middleware to register.

Returns

IDispatcherBuilder

This builder.