-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathQuick.Core.Extensions.FormFactory.pas
More file actions
52 lines (41 loc) · 1.05 KB
/
Quick.Core.Extensions.FormFactory.pas
File metadata and controls
52 lines (41 loc) · 1.05 KB
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
unit Quick.Core.Extensions.FormFactory;
interface
uses
System.SysUtils,
{$IFDEF VCL}
Vcl.Forms,
{$ELSE}
Fmx.Forms,
{$ENDIF}
Quick.Core.DependencyInjection;
type
TFormFactoryServiceExtension = class(TServiceCollectionExtension)
class function AddFormFactory : TServiceCollection;
end;
TFormFactory = class
var
fServiceCollection : TServiceCollection;
public
constructor Create(aServiceCollection : TServiceCollection);
function New<T : TForm, constructor> : T;
end;
implementation
{ TFormFactoryServiceExtension }
class function TFormFactoryServiceExtension.AddFormFactory : TServiceCollection;
begin
Result := ServiceCollection;
Result.AddSingleton<TFormFactory>('',function : TFormFactory
begin
Result := TFormFactory.Create(ServiceCollection);
end);
end;
{ TFormFactory }
constructor TFormFactory.Create(aServiceCollection: TServiceCollection);
begin
fServiceCollection := aServiceCollection;
end;
function TFormFactory.New<T>: T;
begin
Result := fServiceCollection.AbstractFactory<T>;
end;
end.