@@ -100,6 +100,7 @@ TIocRegistration<T> = record
100
100
function GetKey (aPInfo : PTypeInfo; const aName : string = ' ' ): string;
101
101
function RegisterType (aTypeInfo : PTypeInfo; aImplementation : TClass; const aName : string = ' ' ) : TIocRegistration;
102
102
function RegisterInstance (aTypeInfo : PTypeInfo; const aName : string = ' ' ) : TIocRegistration;
103
+ procedure Unregister (aTypeInfo : PTypeInfo; const aName : string = ' ' );
103
104
end ;
104
105
105
106
TIocRegistrator = class (TInterfacedObject,IIocRegistrator)
@@ -120,13 +121,16 @@ TIocRegistrator = class(TInterfacedObject,IIocRegistrator)
120
121
function RegisterInstance <T : class >(const aName : string = ' ' ) : TIocRegistration<T>; overload;
121
122
function RegisterInstance <TInterface : IInterface>(aInstance : TInterface; const aName : string = ' ' ) : TIocRegistration; overload;
122
123
function RegisterOptions <T : TOptions>(aOptions : T) : TIocRegistration<T>;
124
+ procedure Unregister <TInterface: IInterface>(const aName : string = ' ' ); overload;
125
+ procedure Unregister (aTypeInfo : PTypeInfo; const aName : string = ' ' ); overload;
123
126
end ;
124
127
125
128
IIocContainer = interface
126
129
[' {6A486E3C-C5E8-4BE5-8382-7B9BCCFC1BC3}' ]
127
130
function RegisterType (aInterface: PTypeInfo; aImplementation : TClass; const aName : string = ' ' ) : TIocRegistration;
128
131
function RegisterInstance (aTypeInfo : PTypeInfo; const aName : string = ' ' ) : TIocRegistration;
129
132
function Resolve (aServiceType: PTypeInfo; const aName : string = ' ' ): TValue;
133
+ procedure Unregister (aTypeInfo : PTypeInfo; const aName : string = ' ' );
130
134
procedure Build ;
131
135
end ;
132
136
@@ -214,6 +218,8 @@ TIocContainer = class(TInterfacedObject,IIocContainer)
214
218
function AbstractFactory <T : class , constructor > : T; overload;
215
219
function RegisterTypedFactory <TFactoryInterface : IInterface; TFactoryType : class , constructor >(const aName : string = ' ' ) : TIocRegistration<TTypedFactory<TFactoryType>>;
216
220
function RegisterSimpleFactory <TInterface : IInterface; TImplementation : class , constructor >(const aName : string = ' ' ) : TIocRegistration;
221
+ procedure Unregister <TInterface: IInterface>(const aName : string = ' ' ); overload;
222
+ procedure Unregister (aInterface: PTypeInfo; const aName : string = ' ' ); overload;
217
223
procedure Build ;
218
224
end ;
219
225
@@ -375,6 +381,17 @@ function TIocContainer.RegisterType(aInterface: PTypeInfo; aImplementation: TCla
375
381
Result := fRegistrator.RegisterType(aInterface,aImplementation,aName);
376
382
end ;
377
383
384
+ procedure TIocContainer.Unregister <TInterface>(const aName : string = ' ' );
385
+ begin
386
+ fRegistrator.Unregister<TInterface>(aName);
387
+ end ;
388
+
389
+ procedure TIocContainer.Unregister (aInterface: PTypeInfo; const aName : string = ' ' );
390
+ begin
391
+ fRegistrator.Unregister(aInterface, aName);
392
+ end ;
393
+
394
+
378
395
function TIocContainer.RegisterInstance <T>(const aName: string): TIocRegistration<T>;
379
396
begin
380
397
Result := fRegistrator.RegisterInstance<T>(aName);
@@ -601,6 +618,31 @@ function TIocRegistrator.RegisterType(aTypeInfo : PTypeInfo; aImplementation : T
601
618
fDependencyOrder.Add(Result);
602
619
end ;
603
620
621
+ procedure TIocRegistrator.Unregister <TInterface>(const aName : string);
622
+ begin
623
+ Unregister(TypeInfo(TInterface), aName);
624
+ end ;
625
+
626
+ procedure TIocRegistrator.Unregister (aTypeInfo : PTypeInfo; const aName : string);
627
+ var
628
+ key: string;
629
+ vValue: TIocRegistration;
630
+ begin
631
+ key := GetKey(aTypeInfo, aName);
632
+
633
+ if fDependencies.TryGetValue(key,vValue) then
634
+ begin
635
+ if (vValue.IntfInfo = aTypeInfo) and (vValue.Name = aName) then
636
+ begin
637
+ if fDependencyOrder.Contains(vValue) then
638
+ fDependencyOrder.Remove(vValue);
639
+ fDependencies.Remove(key);
640
+ vValue.Free;
641
+ end ;
642
+ end ;
643
+
644
+ end ;
645
+
604
646
{ TIocResolver }
605
647
606
648
constructor TIocResolver.Create(aRegistrator : TIocRegistrator; aInjector : TIocInjector);
0 commit comments