-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMVCBr.Patterns.Builder.pas
751 lines (658 loc) · 18.6 KB
/
MVCBr.Patterns.Builder.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
{ *************************************************************************** }
{ }
{ MVCBr é o resultado de esforços de um grupo }
{ }
{ Copyright (C) 2017 MVCBr }
{ }
{ amarildo lacerda }
{ http://www.tireideletra.com.br }
{ }
{ }
{ *************************************************************************** }
{ }
{ 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. }
{ }
{ *************************************************************************** }
unit MVCBr.Patterns.Builder;
interface
uses
System.Classes, System.SysUtils,
System.RTTI.Helper,
System.RTTI, System.Generics.Collections;
type
IMVCBrBuilderItem<T: Class> = interface(TFunc<T>)
property Instance: T read Invoke;
function IsCreated: Boolean;
function Response: TValue;
procedure FreeInstance;
end;
TMVCBrBuilderItem<T, TResult> = class;
IMVCBrBuilderItem<T, TResult> = interface
['{0EA84140-4B56-494B-8C09-B39A3E7F400F}']
procedure Release;
function This: TObject;
function Execute(AParam: T): TResult;
function Response: TResult;
function Delegate: TFunc<T, TResult>;
function Command: TValue;
procedure SetDelegate(AValue: TFunc<T, TResult>);
end;
TMVCBrBuilder<T, TResult> = class
private
[weak]
FList: TThreadList<IMVCBrBuilderItem<T, TResult>>;
function GetItems(index: integer): TMVCBrBuilderItem<T, TResult>;
public
constructor Create; virtual;
destructor Destroy; override;
class function New: TMVCBrBuilder<T, TResult>; overload;
class function New(ACommand: TValue; ABuilderFunc: TFunc<T, TResult>)
: TMVCBrBuilder<T, TResult>; overload;
function LockList: TList<IMVCBrBuilderItem<T, TResult>>; virtual;
procedure UnlockList; virtual;
function Add(ACommand: TValue; ABuilderFunc: TFunc<T, TResult>)
: TMVCBrBuilderItem<T, TResult>; overload; virtual;
function Add(ACommand: TValue; AItem: TMVCBrBuilderItem<T, TResult>)
: TMVCBrBuilderItem<T, TResult>; overload; virtual;
[weak]
function Execute(ACommand: TValue; AParam: T): TResult; virtual;
[weak]
function Query(ACommand: TValue): TMVCBrBuilderItem<T, TResult>; virtual;
procedure Release; virtual;
procedure Clear; virtual;
function Count: integer; virtual;
property Items[index: integer]: TMVCBrBuilderItem<T, TResult> read GetItems;
function IndexOf(ACommand: TValue): integer;
procedure Remove(AItem: TMVCBrBuilderItem<T, TResult>); overload; virtual;
procedure Remove(ACommand: TValue); overload; virtual;
function Contains(ACommand: TValue): Boolean; virtual;
function This: TObject; virtual;
function isValid(idx: integer): Boolean;
end;
IMVCBrBuilder<T, TResult> = interface
['{1C86D407-8F67-411F-AEA8-D90BBC6AA91A}']
procedure Release;
function This: TObject;
function Add(ACommand: TValue; ABuilderFunc: TFunc<T, TResult>)
: IMVCBrBuilderItem<T, TResult>;
function Query(ACommand: TValue): IMVCBrBuilderItem<T, TResult>;
function Execute(ACommand: TValue; AParam: T): TResult;
function Contains(ACommand: TValue): Boolean;
procedure Remove(ACommand: TValue);
end;
TMVCBrBuilderItem<T, TResult> = Class(TInterfacedObject,
IMVCBrBuilderItem<T, TResult>)
public
private
FCommand: TValue;
FDelegate: TFunc<T, TResult>;
FResult: TResult;
[weak]
FBuilder: TMVCBrBuilder<T, TResult>;
protected
function GetInstance: TMVCBrBuilder<T, TResult>; virtual;
public
constructor Create(ABuilder: TMVCBrBuilder<T, TResult>; ACommand: TValue;
ADelegate: TFunc<T, TResult>); overload; virtual;
destructor Destroy; override;
class function New(ABuilder: TMVCBrBuilder<T, TResult>; ACommand: TValue;
ADelegate: TFunc<T, TResult>): TMVCBrBuilderItem<T, TResult>; overload;
class function New(ABuilder: TMVCBrBuilder<T, TResult>; ACommand: TValue)
: TMVCBrBuilderItem<T, TResult>; overload;
[weak]
function Execute(AParam: T): TResult; virtual;
function Response: TResult; virtual;
function Delegate: TFunc<T, TResult>; virtual;
function Command: TValue; virtual;
procedure SetDelegate(AValue: TFunc<T, TResult>); virtual;
procedure Release; virtual;
function This: TObject; virtual;
function ThisAs: TMVCBrBuilderItem<T, TResult>; virtual;
property DefaultBuilder: TMVCBrBuilder<T, TResult> read GetInstance;
function LockList: TList<IMVCBrBuilderItem<T, TResult>>; virtual;
procedure UnlockList;
end;
TMVCBrBuilderFactory<T, TResult> = class(TInterfacedObject,
IMVCBrBuilder<T, TResult>)
private
[weak]
FWrapper: TMVCBrBuilder<T, TResult>;
protected
public
constructor Create(AClass: TMVCBrBuilder<T, TResult>); virtual;
destructor Destroy; override;
class function New: IMVCBrBuilder<T, TResult>; virtual;
property Builder: TMVCBrBuilder<T, TResult> read FWrapper;
function This: TObject; virtual;
procedure Release; virtual;
function Count: integer; virtual;
[weak]
function Add(ACommand: TValue; ABuilderFunc: TFunc<T, TResult>)
: IMVCBrBuilderItem<T, TResult>; overload; virtual;
[weak]
function Execute(ACommand: TValue; AParam: T): TResult; virtual;
[weak]
function Query(ACommand: TValue): IMVCBrBuilderItem<T, TResult>; virtual;
procedure Remove(ACommand: TValue); overload; virtual;
function Contains(ACommand: TValue): Boolean; virtual;
function LockList: TList<IMVCBrBuilderItem<T, TResult>>; virtual;
procedure UnlockList; virtual;
end;
/// Lazy Builder Object
///
IMVCBrBuilderObject = interface
['{EA4D8260-900F-4627-A7C8-B58CBAB26463}']
function Execute(AParam: TValue): TValue;
procedure SetResponse(const Value: TValue);
function GetResponse: TValue;
property Response: TValue read GetResponse write SetResponse;
end;
TMVCBrBuilderObject = class(TInterfacedObject, IMVCBrBuilderObject)
private
FResponse: TValue;
protected
procedure SetResponse(const Value: TValue); virtual;
function GetResponse: TValue; virtual;
public
function Execute(AParam: TValue): TValue; virtual;
property Response: TValue read GetResponse write SetResponse;
end;
TMVCBrBuilderObjectClass = class of TMVCBrBuilderObject;
IMVCBrBuilderItemResult = IMVCBrBuilderItem<TValue, TValue>;
/// Lazy Builder Item
TMVCBrBuilderLazyItem = class(TMVCBrBuilderItem<TValue, TValue>,
IMVCBrBuilderItem<TObject>)
private
FDelegateTo: TFunc<TObject>;
FClass: TClass;
[weak]
FInstance: TObject;
FCreated: Boolean;
protected
function Invoke: TObject;
public
constructor Create; Overload;
destructor Destroy; override;
class Function New(ABuilder: TMVCBrBuilder<TValue, TValue>;
ACommand: TValue): TMVCBrBuilderLazyItem;
property Instance: TObject read Invoke;
procedure FreeInstance;
[weak]
function Execute(AParam: TValue): TValue; override;
function Response: TValue; Override;
function IsCreated: Boolean; virtual;
function DelegateTo(AFunc: TFunc<TObject>): TMVCBrBuilderLazyItem;
end;
/// Lazy Builder Factory
///
TMVCBrBuilderLazyFactory = class(TMVCBrBuilder<TValue, TValue>)
private
public
class function New: TMVCBrBuilderLazyFactory; virtual;
function Add(ACommand: TValue; AClass: TClass)
: TMVCBrBuilderLazyItem; virtual;
[weak]
function Query<T: Class>(ACommand: TValue): T; overload;
procedure FreeInstance(ACommand: TValue); virtual;
procedure FreeAllInstances; virtual;
end;
implementation
{ TMVCBrBuilderFactory<T> }
uses MVCBr.Interf, System.Classes.Helper;
function TMVCBrBuilder<T, TResult>.Add(ACommand: TValue;
ABuilderFunc: TFunc<T, TResult>): TMVCBrBuilderItem<T, TResult>;
begin
result := TMVCBrBuilderItem<T, TResult>.New(self, ACommand, ABuilderFunc);
FList.Add(result);
end;
function TMVCBrBuilder<T, TResult>.Add(ACommand: TValue;
AItem: TMVCBrBuilderItem<T, TResult>): TMVCBrBuilderItem<T, TResult>;
begin
result := AItem;
FList.Add(result);
end;
procedure TMVCBrBuilder<T, TResult>.Clear;
begin
Release;
FList.Clear;
end;
constructor TMVCBrBuilder<T, TResult>.Create();
begin
FList := TThreadList < IMVCBrBuilderItem < T, TResult >>.Create;
end;
destructor TMVCBrBuilder<T, TResult>.Destroy;
var
i: integer;
begin
FList.free;
FList := nil;
inherited;
end;
function TMVCBrBuilder<T, TResult>.Contains(ACommand: TValue): Boolean;
var
i: integer;
begin
try
i := IndexOf(ACommand);
result := isValid(i);
except
/// workaround early freed interface
result := false;
end;
end;
function TMVCBrBuilder<T, TResult>.Count: integer;
begin
with FList.LockList do
try
result := Count;
finally
FList.UnlockList;
end;
end;
class function TMVCBrBuilder<T, TResult>.New(ACommand: TValue;
ABuilderFunc: TFunc<T, TResult>): TMVCBrBuilder<T, TResult>;
begin
result := TMVCBrBuilder<T, TResult>.New;
result.Add(ACommand, ABuilderFunc);
end;
function TMVCBrBuilder<T, TResult>.Query(ACommand: TValue)
: TMVCBrBuilderItem<T, TResult>;
var
i: integer;
begin
result := nil;
i := IndexOf(ACommand);
if isValid(i) then
with FList.LockList do
try
result := TMVCBrBuilderItem<T, TResult>(Items[i].This);
finally
FList.UnlockList;
end;
end;
function TMVCBrBuilder<T, TResult>.Execute(ACommand: TValue; AParam: T)
: TResult;
var
AQuery: TMVCBrBuilderItem<T, TResult>;
begin
AQuery := Query(ACommand);
Assert(assigned(AQuery), 'Builder Command not found');
if assigned(AQuery) then
begin
result := AQuery.Execute(AParam);
end;
end;
function TMVCBrBuilder<T, TResult>.GetItems(index: integer)
: TMVCBrBuilderItem<T, TResult>;
begin
with LockList do
try
result := TMVCBrBuilderItem<T, TResult>(Items[index].This);
finally
UnlockList;
end;
end;
function TMVCBrBuilder<T, TResult>.IndexOf(ACommand: TValue): integer;
var
i: integer;
begin
i := -1;
with FList.LockList do
try
for i := Count - 1 downto 0 do
begin
if TMVCBrBuilderItem<T, TResult>(Items[i].This).FCommand.Equals(ACommand)
then
begin
result := i;
exit;
end;
end;
finally
FList.UnlockList;
end;
end;
function TMVCBrBuilder<T, TResult>.isValid(idx: integer): Boolean;
begin
result := (idx >= 0) and (idx < Count);
end;
function TMVCBrBuilder<T, TResult>.LockList
: TList<IMVCBrBuilderItem<T, TResult>>;
begin
result := FList.LockList;
end;
class function TMVCBrBuilder<T, TResult>.New: TMVCBrBuilder<T, TResult>;
begin
result := TMVCBrBuilder<T, TResult>.Create;
end;
procedure TMVCBrBuilder<T, TResult>.Release;
var
i: integer;
begin
{
with FList.LockList do
try
for i := count - 1 downto 0 do
try
items[i].Release;
except
/// workaround;
end;
finally
FList.UnlockList;
end;
}
end;
procedure TMVCBrBuilder<T, TResult>.Remove(ACommand: TValue);
var
i: integer;
begin
i := IndexOf(ACommand);
if isValid(i) then
with FList.LockList do
try
Delete(i);
finally
FList.UnlockList;
end;
end;
procedure TMVCBrBuilder<T, TResult>.Remove
(AItem: TMVCBrBuilderItem<T, TResult>);
begin
try
if Contains(AItem.FCommand) then
begin
AItem.Release;
Remove(AItem.FCommand);
end;
except
/// workaroud for early freed
end;
end;
function TMVCBrBuilder<T, TResult>.This: TObject;
begin
result := self;
end;
procedure TMVCBrBuilder<T, TResult>.UnlockList;
begin
FList.UnlockList;
end;
{ TMVCBrBuilderItem<T> }
function TMVCBrBuilderItem<T, TResult>.Delegate: TFunc<T, TResult>;
begin
result := FDelegate;
end;
destructor TMVCBrBuilderItem<T, TResult>.Destroy;
begin
inherited;
end;
function TMVCBrBuilderItem<T, TResult>.Execute(AParam: T): TResult;
begin
if assigned(FDelegate) then
begin
FResult := FDelegate(AParam);
result := FResult;
end;
end;
function TMVCBrBuilderItem<T, TResult>.GetInstance: TMVCBrBuilder<T, TResult>;
begin
result := FBuilder;
end;
function TMVCBrBuilderItem<T, TResult>.LockList
: TList<IMVCBrBuilderItem<T, TResult>>;
begin
result := FBuilder.LockList;
end;
class function TMVCBrBuilderItem<T, TResult>.New
(ABuilder: TMVCBrBuilder<T, TResult>; ACommand: TValue)
: TMVCBrBuilderItem<T, TResult>;
begin
result := New(ABuilder, ACommand, nil);
end;
class function TMVCBrBuilderItem<T, TResult>.New
(ABuilder: TMVCBrBuilder<T, TResult>; ACommand: TValue;
ADelegate: TFunc<T, TResult>): TMVCBrBuilderItem<T, TResult>;
begin
result := TMVCBrBuilderItem<T, TResult>.Create(ABuilder, ACommand, ADelegate);
end;
function TMVCBrBuilderItem<T, TResult>.Command: TValue;
begin
result := FCommand;
end;
constructor TMVCBrBuilderItem<T, TResult>.Create
(ABuilder: TMVCBrBuilder<T, TResult>; ACommand: TValue;
ADelegate: TFunc<T, TResult>);
begin
inherited Create;
FCommand := ACommand;
FDelegate := ADelegate;
FBuilder := ABuilder;
end;
procedure TMVCBrBuilderItem<T, TResult>.Release;
begin
if assigned(FBuilder) then
FBuilder.Remove(self);
FBuilder := nil;
end;
function TMVCBrBuilderItem<T, TResult>.Response: TResult;
begin
result := FResult;
end;
procedure TMVCBrBuilderItem<T, TResult>.SetDelegate(AValue: TFunc<T, TResult>);
begin
FDelegate := AValue;
end;
function TMVCBrBuilderItem<T, TResult>.This: TObject;
begin
result := self;
end;
function TMVCBrBuilderItem<T, TResult>.ThisAs: TMVCBrBuilderItem<T, TResult>;
begin
result := self;
end;
procedure TMVCBrBuilderItem<T, TResult>.UnlockList;
begin
FBuilder.UnlockList;
end;
{ TMVCBrBuilderFactory<T, TResult> }
function TMVCBrBuilderFactory<T, TResult>.Add(ACommand: TValue;
ABuilderFunc: TFunc<T, TResult>): IMVCBrBuilderItem<T, TResult>;
begin
result := FWrapper.Add(ACommand, ABuilderFunc);
end;
function TMVCBrBuilderFactory<T, TResult>.Contains(ACommand: TValue): Boolean;
begin
result := FWrapper.Contains(ACommand);
end;
function TMVCBrBuilderFactory<T, TResult>.Count: integer;
begin
result := FWrapper.Count;
end;
constructor TMVCBrBuilderFactory<T, TResult>.Create
(AClass: TMVCBrBuilder<T, TResult>);
begin
inherited Create;
FWrapper := AClass;
end;
destructor TMVCBrBuilderFactory<T, TResult>.Destroy;
begin
if assigned(FWrapper) then
FWrapper.free;
inherited;
end;
function TMVCBrBuilderFactory<T, TResult>.Execute(ACommand: TValue;
AParam: T): TResult;
begin
result := FWrapper.Execute(ACommand, AParam);
end;
function TMVCBrBuilderFactory<T, TResult>.LockList
: TList<IMVCBrBuilderItem<T, TResult>>;
begin
result := FWrapper.LockList;
end;
class function TMVCBrBuilderFactory<T, TResult>.New: IMVCBrBuilder<T, TResult>;
begin
result := TMVCBrBuilderFactory<T, TResult>.Create
(TMVCBrBuilder<T, TResult>.Create);
end;
function TMVCBrBuilderFactory<T, TResult>.Query(ACommand: TValue)
: IMVCBrBuilderItem<T, TResult>;
begin
result := FWrapper.Query(ACommand);
end;
procedure TMVCBrBuilderFactory<T, TResult>.Release;
begin
if assigned(FWrapper) then
FWrapper.Release;
end;
procedure TMVCBrBuilderFactory<T, TResult>.Remove(ACommand: TValue);
begin
FWrapper.Remove(ACommand);
end;
function TMVCBrBuilderFactory<T, TResult>.This: TObject;
begin
result := self;
end;
procedure TMVCBrBuilderFactory<T, TResult>.UnlockList;
begin
FWrapper.UnlockList;
end;
{ TMVCBBuilderLazyItem<T, TResult> }
constructor TMVCBrBuilderLazyItem.Create;
begin
raise Exception.Create
('Abstract... Use NEW class function instead of create');
end;
function TMVCBrBuilderLazyItem.DelegateTo(AFunc: TFunc<TObject>)
: TMVCBrBuilderLazyItem;
begin
result := self;
FDelegateTo := AFunc;
end;
destructor TMVCBrBuilderLazyItem.Destroy;
var
Interf: IInterface;
begin
try
if supports(FInstance, IInterface, Interf) then
Interf := nil
else
FreeAndNil(FInstance);
/// workaround - with Free blow Exception Error
except
end;
inherited;
end;
function TMVCBrBuilderLazyItem.Execute(AParam: TValue): TValue;
begin
with TMVCBrBuilderObject(Instance) do
begin
Response := Execute(AParam);
result := Response;
end;
end;
procedure TMVCBrBuilderLazyItem.FreeInstance;
begin
FreeAndNil(FInstance);
FCreated := false;
end;
function TMVCBrBuilderLazyItem.Invoke: TObject;
begin
if not FCreated then
begin
if assigned(FDelegateTo) then
FInstance := FDelegateTo;
if not assigned(FInstance) then
FInstance := FClass.Create;
FCreated := true;
end;
result := FInstance;
end;
function TMVCBrBuilderLazyItem.IsCreated: Boolean;
begin
result := FCreated;
end;
class function TMVCBrBuilderLazyItem.New
(ABuilder: TMVCBrBuilder<TValue, TValue>; ACommand: TValue)
: TMVCBrBuilderLazyItem;
begin
result := inherited Create();
result.FBuilder := ABuilder;
result.FCommand := ACommand;
end;
function TMVCBrBuilderLazyItem.Response: TValue;
begin
result := TMVCBrBuilderObject(Instance).Response;
end;
{ TMVCBBuilderObject }
function TMVCBrBuilderObject.Execute(AParam: TValue): TValue;
begin
end;
function TMVCBrBuilderObject.GetResponse: TValue;
begin
result := FResponse
end;
procedure TMVCBrBuilderObject.SetResponse(const Value: TValue);
begin
FResponse := Value;
end;
{ TMVCBBuilderLazyFactory }
function TMVCBrBuilderLazyFactory.Add(ACommand: TValue; AClass: TClass)
: TMVCBrBuilderLazyItem;
begin
result := TMVCBrBuilderLazyItem.New(self, ACommand);
result.FClass := AClass;
result.FInstance := nil;
inherited Add(ACommand, result);
end;
procedure TMVCBrBuilderLazyFactory.FreeAllInstances;
var
i: integer;
begin
With FList.LockList do
try
for i := 0 to Count - 1 do
TMVCBrBuilderLazyItem(Items[i]).FreeInstance;
finally
FList.UnlockList;
end;
end;
procedure TMVCBrBuilderLazyFactory.FreeInstance(ACommand: TValue);
var
i: integer;
begin
i := IndexOf(ACommand);
if isValid(i) then
With FList.LockList do
try
TMVCBrBuilderLazyItem(Items[i]).FreeInstance;
finally
FList.UnlockList;
end;
end;
class function TMVCBrBuilderLazyFactory.New: TMVCBrBuilderLazyFactory;
begin
result := TMVCBrBuilderLazyFactory.Create;
end;
function TMVCBrBuilderLazyFactory.Query<T>(ACommand: TValue): T;
var
ret: IMVCBrBuilderItem<TValue, TValue>;
AGuid: TGuid;
AItem: TMVCBrBuilderLazyItem;
begin
ret := inherited Query(ACommand);
AItem := TMVCBrBuilderLazyItem(ret.This);
result := T(AItem.Instance);
ret := nil;
end;
end.