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
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
pathstringThe 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
TServiceThe 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
pathis 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
prefixstringThe prefix of this route. This prefix will be compared with the start of the path of the request.
Returns
- IDispatcherBuilder
This builder.
Type Parameters
TServiceThe 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
prefixis 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
prefixstringThe prefix of the route to the sub-router.
configureAction<IDispatcherBuilder>A delegate that configures the new sub-router.
Use(Func<IDispatcher, IDispatcher>)
Registers a middleware.
IDispatcherBuilder Use(Func<IDispatcher, IDispatcher> middleware)
Parameters
middlewareFunc<IDispatcher, IDispatcher>The middleware to register.
Returns
- IDispatcherBuilder
This builder.