getLazyMiddleware<T> function

Middleware<T> getLazyMiddleware<T>(
  1. LazyMiddlewareFactory<T> factory
)

Lazily asynchronously gets middleware

Example:

getLazyMiddleware((context) async {
  final route = await getSomeRoute(context.path) // Future<Function>;

  return route;
});

Implementation

Middleware<T> getLazyMiddleware<T>(LazyMiddlewareFactory<T> factory) {
  Middleware<T>? middleware;

  return (context, next) async {
    middleware ??= await factory(context);

    return middleware!(context, next);
  };
}