I'm just getting started with the Delphi Spring Framework and was wondering whether the current version of the DI container somehow allows delegating the construction to a factory method without specifying an implementing type?
E.g. something similar to this:
GlobalContainer
.RegisterFactory<ISomeObject>(
function: ISomeObject
begin
Result := CreateComObject(CLASS_SomeObject) as ISomeObject;
end)
.Implements<ISomeObject> // could probably be implied from the above
.AsSingletonPerThread;
As you can see, my specific use case is the instantiation of COM objects. In that case the class implementing the interface I'm interested in is not part of my application but I am still able to create instances by calling CreateComObject
/ CoCreateInstance
. However, it seems I'm out of luck as registrations in the Container always appear to be bound to an actual implementing class.
Assuming this isn't possible as such at the moment, how would you experts out there address this? Would you create a wrapper class or dummy class or would you simply keep COM objects out of the DI container and simply instantiate them via CreateComObject
?