getLazyMiddleware<T> function
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);
};
}