forked from zamronypj/fano-app-middleware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyapp.pas
97 lines (82 loc) · 2.8 KB
/
myapp.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(*!------------------------------------------------------------
* Fano Web Framework Skeleton Application (https://fanoframework.github.io)
*
* @link https://github.com/fanoframework/fano-app-middleware
* @copyright Copyright (c) 2018 Zamrony P. Juhara
* @license https://github.com/fanoframework/fano-app-middleware/blob/master/LICENSE (GPL 3.0)
*------------------------------------------------------------- *)
unit myapp;
interface
uses
fano;
type
TMyAppServiceProvider = class(TBasicAppServiceProvider)
protected
function buildAppConfig(const ctnr : IDependencyContainer) : IAppConfiguration; override;
function buildDispatcher(
const ctnr : IDependencyContainer;
const routeMatcher : IRouteMatcher;
const config : IAppConfiguration
) : IDispatcher; override;
public
procedure register(const container : IDependencyContainer); override;
end;
TMyAppRoutes = class(TRouteBuilder)
public
procedure buildRoutes(
const container : IDependencyContainer;
const router : IRouter
); override;
end;
implementation
uses
sysutils,
{*! -------------------------------
controllers factory
----------------------------------- *}
HiControllerFactory,
{*! -------------------------------
middlewares factory
----------------------------------- *}
AjaxOnlyMiddlewareFactory;
function TMyAppServiceProvider.buildAppConfig(const ctnr : IDependencyContainer) : IAppConfiguration;
begin
ctnr.add(
'config',
TJsonFileConfigFactory.create(
extractFileDir(getCurrentDir()) + '/app/config/config.json'
)
);
result := ctnr.get('config') as IAppConfiguration;
end;
function TMyAppServiceProvider.buildDispatcher(
const ctnr : IDependencyContainer;
const routeMatcher : IRouteMatcher;
const config : IAppConfiguration
) : IDispatcher;
var dispatcherSvc : string;
begin
ctnr.add('appMiddlewares', TMiddlewareListFactory.create());
dispatcherSvc := GuidToString(IDispatcher);
ctnr.add(
dispatcherSvc,
TDispatcherFactory.create(
ctnr.get('appMiddlewares') as IMiddlewareLinkList,
routeMatcher,
TRequestResponseFactory.create()
)
);
result := ctnr.get(dispatcherSvc) as IDispatcher;
end;
procedure TMyAppServiceProvider.register(const container : IDependencyContainer);
begin
{$INCLUDE Dependencies/dependencies.inc}
end;
procedure TMyAppRoutes.buildRoutes(
const container : IDependencyContainer;
const router : IRouter
);
begin
{$INCLUDE Routes/routes.inc}
end;
end.