read<T> method

T read<T>()

Lookup an instance of T from the request context.

A StateError is thrown if T is not available within the provided request context.


T read<T>() {
  final value = request._request.context['$T'];
  if (value == null) {
    throw StateError(
      '''<$T>() called with a request context that does not contain a $T.

This can happen if $T was not provided to the request context:
// _middleware.dart
Handler middleware(Handler handler) {
  return handler.use(provider<T>((context) => $T());
  return (value as T Function())();