I'm new to Spring4D and trying to understand how to combine DIContainers with lazy loaded objects. I think i get the concept of pushing all the creation of the objects back in the callstack to the root of the application and register the types and invoke something or pass the solved objects using constructor/property/method injection. This way the project will only get dependency to interfaces in the seperate units and only get dependency to Spring in the root unit.
IMyClass = interface ['{593ABC29-B882-4B70-903F-52F381DD53BF}']
procedure DoSomething;
end;
TMyClass = class(TInterfacedObject, IMyClass)
public
procedure DoSomething;
end;
// In root of application
Container.RegisterType<TMyClass>;
Container.Resolve<IMyClass>.DoSomething;
I see Spring4D has something called Lazy<T> for lazy loading, so in following example an instance of TMyClass is not created before referencing Value e.g.
var LazyMyClassObjectFactory := TLazy<TMyClass>.Create;
LazyMyClassObjectFactory.Value.DoSomething;
My problem is 1. how do i combine a DIContainer with lazy loading (not quite sure how to resolve the interfaced lazy objects) and 2. can it be done without requiring Lazy<T> since i dont like the idea of becoming dependant on "spring" in all my units.