We use the dependency injection framework from Spring4D and have an issue with the way it constructs objects if it cannot resolve all constructor parameters. In our case all parameters of the constructor of the ancestor can be resolved and it looks like that Spring4D now uses this constructor. Even if we reintroduce
the constructor the descedant, it still uses the constructor of the ancestor.
However, the behavior I would expect (and prefer) is that the resolving fails if it cannot find a correct constructor for the interface you try to resolve.
Example:
TMyClass = class(TInterfacedObject, IMyClass)
constructor Create(ARequester: IRequester);
end;
TMyDescendant = class(TMyClass, IMyDescendant)
constructor Create(ARequester: IRequester; AnotherRequester: IOtherRequester);
end;
GlobalContainer.Resolve<IMyDescendant>
In this example it will call the constructor of TMyClass
if there is no class registered that implements IOtherRequester
. This means that any Guard.IsNotNull
that are in the constructor of TMyDescendant
doesn't work, because that constructor is never called.
Are there ways to resolve this? Of course we could override the constructor of TMyClass
in TMyDescendant
, but I prefer a more clean way to do this.