Dispatcher task

In general, task of a dispatcher is quite simple. Given request uri, it must find instance of class that will handle the request, passing all relevant information and execute it.

A dispatcher in Fano Framework must implements IDispatcher interface.

IDispatcher = interface
    function dispatchRequest(const env: ICGIEnvironment) : IResponse;
  • env, CGI environment variable that is given by web server.

Built-in Dispatcher implementation

Fano Framework comes with two dispatcher implementation, TSimpleDispatcher and TDispatcher class.

TSimpleDispatcher is light-weight dispatcher that does not offer middleware layer while the latter supports middleware.

Creating dispatcher

Creating simple dispatcher:

var router : IRouteMatcher;
container.add('dispatcher', TSimpleDispatcherFactory.create(router));

Creating basic dispatcher with middleware support

var router : IRouteMatcher;
container.add('dispatcher', TDispatcherFactory.create(router));

Set dispatcher

Fano Framework allows application to change dispatcher implementation to use and can be set in initDispatcher(). In this method implementation, you must returns instance of dispatcher.

function TMyApp.initDispatcher(const container : IDependencyContainer) : IDispatcher;
    result := container.get('dispatcher') as IDispatcher;