delphimvcframework/samples/jsonrpc_with_published_objects/MainWebModuleU.pas
2020-08-05 09:50:06 +02:00

77 lines
1.3 KiB
ObjectPascal

unit MainWebModuleU;
interface
uses
System.SysUtils,
System.Classes,
Web.HTTPApp,
MVCFramework,
FireDAC.Stan.Intf,
FireDAC.Stan.Option,
FireDAC.Stan.Param,
FireDAC.Stan.Error,
FireDAC.DatS,
FireDAC.Phys.Intf,
FireDAC.DApt.Intf,
Data.DB,
FireDAC.Comp.DataSet,
FireDAC.Comp.Client;
type
TMyWebModule = class(TWebModule)
procedure WebModuleCreate(Sender: TObject);
procedure WebModuleDestroy(Sender: TObject);
private
FMVC: TMVCEngine;
public
{ Public declarations }
end;
var
WebModuleClass: TComponentClass = TMyWebModule;
implementation
{$R *.dfm}
uses
System.IOUtils,
MVCFramework.Commons,
MyObjectU,
MVCFramework.JSONRPC,
MVCFramework.Middleware.CORS,
MainDM;
procedure TMyWebModule.WebModuleCreate(Sender: TObject);
begin
FMVC := TMVCEngine.Create(Self);
FMVC.PublishObject(
function: TObject
begin
Result := TMyObject.Create;
end, '/jsonrpc');
FMVC.PublishObject(
function: TObject
begin
Result := TdmMain.Create(nil);
end, '/rpcdatamodule');
FMVC.PublishObject(
function: TObject
begin
Result := TMyObjectWithHooks.Create;
end, '/jsonrpchooks');
FMVC.AddMiddleware(TCORSMiddleware.Create());
end;
procedure TMyWebModule.WebModuleDestroy(Sender: TObject);
begin
FMVC.Free;
end;
end.