- edited description
Constructor default values are ignored
We have a class having a default value in the constructor, when Spring tries to resolve the object the default value is ignored:
A class like this:
TDefaultValue = class(TInterfacedObject, IDefaultValue)
private
fFirst: Integer;
public
constructor Create(pFirst: Integer = 1);
function GetFirst: Integer;
end;
We are trying to get an instance with:
var
defaultValue: IDefaultValue;
begin
fContainer.RegisterType<TDefaultValue>
.Implements<IDefaultValue>;
fContainer.Build;
defaultValue := fContainer.Resolve<IDefaultValue>;
defaultValue.GetFirst should return 1 but is returning 0
Comments (3)
-
reporter -
repo owner - changed status to wontfix
Unfortunately the RTTI that is used by the DI system does not provide any information about default parameter values thus it cannot pass them.
So either make an overload with no parameter which then calls the one with parameter passing 1 or put the Inject attribute with value 1 (remember to put spring.container.common into the uses) onto the pFirst parameter. That will tell the container to pass 1 into it.
-
reporter FYI. I reported the issue https://quality.embarcadero.com/browse/RSP-21563. Maybe in a future could be possible fix this problem.
- Log in to comment