2017-05-18 00:02:22 +02:00
|
|
|
|
// ***************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// Delphi MVC Framework
|
|
|
|
|
//
|
2021-02-10 11:26:14 +01:00
|
|
|
|
// Copyright (c) 2010-2021 Daniele Teti and the DMVCFramework Team
|
2017-05-18 00:02:22 +02:00
|
|
|
|
//
|
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
|
//
|
|
|
|
|
// Collaborators with this file: Ezequiel Juliano Müller (ezequieljuliano@gmail.com)
|
|
|
|
|
//
|
|
|
|
|
// ***************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
2013-11-10 01:03:53 +01:00
|
|
|
|
unit WebModuleU;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2019-03-10 16:29:18 +01:00
|
|
|
|
System.SysUtils,
|
|
|
|
|
System.Classes,
|
|
|
|
|
Web.HTTPApp,
|
|
|
|
|
MVCFramework,
|
|
|
|
|
FireDAC.Stan.Intf,
|
|
|
|
|
FireDAC.Stan.Option,
|
|
|
|
|
FireDAC.Stan.Error,
|
|
|
|
|
FireDAC.UI.Intf,
|
|
|
|
|
FireDAC.Phys.Intf,
|
|
|
|
|
FireDAC.Stan.Def,
|
|
|
|
|
FireDAC.Stan.Pool,
|
|
|
|
|
FireDAC.Stan.Async,
|
|
|
|
|
FireDAC.Phys,
|
|
|
|
|
FireDAC.Stan.Param,
|
|
|
|
|
FireDAC.DatS,
|
|
|
|
|
FireDAC.DApt.Intf,
|
|
|
|
|
FireDAC.DApt,
|
|
|
|
|
Data.DB,
|
|
|
|
|
FireDAC.Comp.DataSet,
|
|
|
|
|
FireDAC.Comp.Client,
|
|
|
|
|
FireDAC.Phys.IBBase,
|
|
|
|
|
FireDAC.Phys.IB,
|
|
|
|
|
FireDAC.Phys.FB,
|
2017-04-20 23:48:50 +02:00
|
|
|
|
FireDAC.Phys.FBDef;
|
2013-11-10 01:03:53 +01:00
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TWebModule1 = class(TWebModule)
|
|
|
|
|
procedure WebModuleCreate(Sender: TObject);
|
|
|
|
|
private
|
|
|
|
|
DMVC: TMVCEngine;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
WebModuleClass: TComponentClass = TWebModule1;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
2019-03-10 16:29:18 +01:00
|
|
|
|
|
2017-05-18 00:02:22 +02:00
|
|
|
|
uses
|
2017-10-30 14:42:15 +01:00
|
|
|
|
MVCFramework.Commons,
|
|
|
|
|
RenderSampleControllerU,
|
|
|
|
|
CustomTypesU,
|
2017-05-18 00:02:22 +02:00
|
|
|
|
CustomTypesSerializersU,
|
|
|
|
|
MVCFramework.Serializer.Intf,
|
2017-10-30 14:42:15 +01:00
|
|
|
|
System.Generics.Collections,
|
2019-06-25 17:32:30 +02:00
|
|
|
|
MVCFramework.View.Renderers.Mustache,
|
2020-02-26 13:10:41 +01:00
|
|
|
|
MVCFramework.Serializer.JsonDataObjects.OptionalCustomTypes,
|
|
|
|
|
MVCFramework.Logger;
|
2013-11-10 01:03:53 +01:00
|
|
|
|
|
|
|
|
|
procedure TWebModule1.WebModuleCreate(Sender: TObject);
|
|
|
|
|
begin
|
2016-02-26 19:21:57 +01:00
|
|
|
|
DMVC := TMVCEngine.Create(self,
|
|
|
|
|
procedure(Config: TMVCConfig)
|
|
|
|
|
begin
|
2016-02-27 09:58:54 +01:00
|
|
|
|
Config[TMVCConfigKey.ViewPath] := 'templates';
|
2016-02-26 19:21:57 +01:00
|
|
|
|
end);
|
2017-05-18 00:02:22 +02:00
|
|
|
|
|
|
|
|
|
// Now the default json serializer is set, but how to set a different
|
|
|
|
|
// serializer? Check the lines below!
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
// DMVC
|
|
|
|
|
// .Serializers
|
|
|
|
|
// .AddOrSetValue(TMVCMediaType.APPLICATION_JSON, TMVCJSONSerializer.Create);
|
|
|
|
|
// ------------------------------------
|
|
|
|
|
|
2013-11-10 01:03:53 +01:00
|
|
|
|
DMVC.AddController(TRenderSampleController);
|
2017-10-30 14:42:15 +01:00
|
|
|
|
DMVC.SetViewEngine(TMVCMustacheViewEngine);
|
|
|
|
|
|
2017-05-25 10:31:24 +02:00
|
|
|
|
// Register a custom serializer for TUserRoles (is compatible only with the default serializer)
|
2020-02-26 13:10:41 +01:00
|
|
|
|
// DMVC
|
|
|
|
|
// .Serializers
|
|
|
|
|
// .Items[TMVCMediaType.APPLICATION_JSON]
|
|
|
|
|
// .RegisterTypeSerializer(TypeInfo(TUserRoles), TUserRolesSerializer.Create);
|
2019-03-06 12:11:22 +01:00
|
|
|
|
|
2017-10-09 16:17:12 +02:00
|
|
|
|
// You can check how this custom type serializer works
|
2017-05-25 10:31:24 +02:00
|
|
|
|
// calling http://localhost:8080/customserializationtype
|
2017-12-12 18:32:41 +01:00
|
|
|
|
|
|
|
|
|
DMVC
|
|
|
|
|
.Serializers
|
2019-03-06 12:11:22 +01:00
|
|
|
|
.Items[TMVCMediaType.APPLICATION_JSON]
|
2017-12-12 18:32:41 +01:00
|
|
|
|
.RegisterTypeSerializer(TypeInfo(TNullableRecordAlias), TNullableAliasSerializer.Create);
|
2019-06-25 17:32:30 +02:00
|
|
|
|
|
|
|
|
|
// This line registers custom serializers for TBitmap, TPngImage (Only MSWindows) and TJPEGImage (Only MSWindows)
|
2019-07-24 20:48:22 +02:00
|
|
|
|
RegisterOptionalCustomTypesSerializersForJSON(DMVC.Serializers);
|
2013-11-10 01:03:53 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|