I am faced with the problem of properly object instantiating from the type resolved by a Spring4D framework container.
I have a class:
type
TSurvey = class ( TInterfacedObject, ISurvey )
private
_id : Integer;
_organization : IOrganization;
function GetId () : Integer;
procedure SetId ( const value : Integer );
function GetOrganization () : IOrganization;
procedure SetOrganization ( const value : IOrganization);
public
property Id : Integer read GetId write SetId;
property Organization: IOrganization read GetOrganization write SetOrganization;
end;
...
initialization
GlobalContainer.RegisterType<TSurvey>.Implements<ISurvey>.InjectField ( '_organization' );
...
I use the GlobalContainer to instantiate an object:
survey := GlobalContainer.Resolve<ISurvey>;
survey.Organization.Id := 5;
and everything is alright and works perfectly.
Now I want to create a descendant class for TSurvey:
type
TFieldSurvey = class ( TSurvey )
...
end;
And the question is how to correct instantiate an object for TFieldSurvey class?
If I use Create (), then I get an exception:
fieldSurvey := TFieldSurvey.Create ();
fieldSurvey.Organization.Id := 5 <- exception is here
Do I have to explicitly call the constructor for Organization field in TFieldSurvey constructor, or there is another way? For example, using GlobalContainer?
Thanks in advance.