Skip to content

Commit 3acea4b

Browse files
committed
explain why miidleware may not be called
1 parent 063e85d commit 3acea4b

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

Diff for: dispatcher/index.md

+37-3
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ container.add(
106106
)
107107
);
108108
```
109-
## Set dispatcher
109+
## <a name="set-dispatcher"></a> Set dispatcher
110110

111-
Fano Framework allows application to change dispatcher implementation to use by
112-
overriding `buildDispatcher()` method of `TBasicServiceProvider` class. In this method implementation, you must returns
111+
Fano Framework allows application to change dispatcher implementation to use, by
112+
overriding protected `buildDispatcher()` method of `TBasicServiceProvider` class. In this method implementation, you must returns
113113
instance of dispatcher.
114114

115115
```
@@ -119,6 +119,40 @@ begin
119119
end;
120120
```
121121

122+
If you use Fano CLI to [scaffold your web application project](/scaffolding-with-fano-cli), you can declared `buildDispatcher()` in `bootstrap.pas` file as shown in following example.
123+
124+
```
125+
TAppServiceProvider = class(TDaemonAppServiceProvider)
126+
protected
127+
function buildDispatcher(
128+
const ctnr : IDependencyContainer;
129+
const routeMatcher : IRouteMatcher;
130+
const config : IAppConfiguration
131+
) : IDispatcher; override;
132+
...
133+
end;
134+
...
135+
function TAppServiceProvider.buildDispatcher(
136+
const ctnr : IDependencyContainer;
137+
const routeMatcher : IRouteMatcher;
138+
const config : IAppConfiguration
139+
) : IDispatcher;
140+
begin
141+
ctnr.add('appMiddlewares', TMiddlewareListFactory.create());
142+
143+
ctnr.add(
144+
'my-dispatcher',
145+
TDispatcherFactory.create(
146+
ctnr['appMiddlewares'] as IMiddlewareLinkList,
147+
routeMatcher,
148+
TRequestResponseFactory.create()
149+
)
150+
);
151+
result := ctnr['my-dispatcher'] as IDispatcher;
152+
end;
153+
```
154+
See [example of adding dispatcher with middleware support](https://github.com/fanoframework/fano-csrf/blob/master/src/bootstrap.pas).
155+
122156
## Explore more
123157

124158
- [Working with Router](/working-with-router)

Diff for: middlewares/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ var helloCtrlMiddleware : IMiddleware;
362362
helloCtrlMiddleware := TRequestHandlerAsMiddleware.create(helloController);
363363
```
364364

365+
## Middleware issues
366+
367+
### Middleware is not being called
368+
369+
When you attach middleware to a route but middleware is not being called, make sure you use [dispatcher implementation which supports middleware](/dispatcher#set-dispatcher). Middleware support is not enabled by default.
370+
365371
## Performance consideration
366372

367373
Using middleware adds overhead as request must go multiple execution points before reaching actual request handler. Also, you need to aware that each middleware will call next middleware recursively so you should limit number of middlewares in use.

0 commit comments

Comments
 (0)