delphimvcframework/samples/renders/WebModuleU.pas

98 lines
3.1 KiB
ObjectPascal
Raw Normal View History

// ***************************************************************************
//
// Delphi MVC Framework
//
2019-01-08 12:48:27 +01:00
// Copyright (c) 2010-2019 Daniele Teti and the DMVCFramework Team
//
// 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
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,
2016-02-26 19:21:57 +01:00
FireDAC.Comp.Client, FireDAC.Phys.IBBase, FireDAC.Phys.IB, FireDAC.Phys.FB,
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}
uses
MVCFramework.Commons,
RenderSampleControllerU,
CustomTypesU,
CustomTypesSerializersU,
MVCFramework.Serializer.Intf,
System.Generics.Collections,
MVCFramework.View.Renderers.Mustache;
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);
// 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);
DMVC.SetViewEngine(TMVCMustacheViewEngine);
// Register a custom serializer for TUserRoles (is compatible only with the default serializer)
DMVC
.Serializers
2019-03-06 12:11:22 +01:00
.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
// calling http://localhost:8080/customserializationtype
DMVC
.Serializers
2019-03-06 12:11:22 +01:00
.Items[TMVCMediaType.APPLICATION_JSON]
.RegisterTypeSerializer(TypeInfo(TNullableRecordAlias), TNullableAliasSerializer.Create);
2013-11-10 01:03:53 +01:00
end;
end.