This is my second attempt to explain what I am trying to accomplish as I did not explain it very well before.
for this Pseudo example if you have the classes to resolve setup as below;
TOuter.constructor.Create(Name: TName; Inner1, Inner2: TInner);
TInner.constructor.Create(Name: TName; Sub: TSub);
TSub.constructor.Create(Name: TName);
TName.constructor.Create(Name: String);
var Names = TStack<String>.Create;
If it is possible to intercept before and after resolve it would be possible to implement a parent, ancestor or, 'i am being constructed for ...'.
for example
RegisterType<TName>(
function: TName
begin
Result:=TName.Create(String.Join('.',Names.List.ToArray));
end
);
RegisterType<TOuter>;
RegisterType<TInner>;
RegisterType<TSub>;
Resolver.BeforeResolve:=
procedure(ClassType: TClass)
begin
Names.Push(ClassType.ClassName);
end;
Resolver.AfterResolve:=
procedure(ClassType: TClass)
begin
Names.Pop;
end;
Resolve<TOuter> would produce
TOuter
Name = 'Outer'
Inner1 =
Name = 'Outer.Inner'
Sub
Name = 'Outer.Inner.Sub'
Inner2
Name = 'Outer.Inner'
Sub
Name = 'Outer.Inner.Sub'
I did think it might be possible by sub classing the component activator and looking for if classname=TName or if arguments.contains(TName) then ...
For this example I have omitted making the Names stack handle multiple threads and in reality I am not using names but rather having a stack of interfaces each knowing who their 'parent' is but this demonstrates what I am trying to implement.