Using Typhoon dependency injection, is there any way, regular or a hack, to find an assembly by it's class name in runtime? I'm required to load a configuration from a file in one assembly, and that configuration would tell me which other assemblies to use to produce some components needed in the current assembly. Also I don't have all assemblies code (classes) available as I'm working on a reusable (library) code, so it needs to be dynamic and in runtime. Any way at all?
Thanks.
EDIT:
The thing I tried to do is a bit contradictory. I wanted to access other initial assemblies from one initial assembly, while all of them were in the process of being initialized (the point when swizzled setAppDelegate is called, plist TyphoonInitialAssemblies is read and assemblies created). No assembly is activated at that point.
But, managed to do it in a bit strange way, by instantiating an assembly using a class name [[NSClassFromString(assemblyClassName) alloc] init] and performing a selector on the returned object. And it works as long as that assembly is already initialized (appears first in the plist). So, to repeat, all this happens during initial assembly creation (swizzled setAppDelegate).
I'm just not sure if this approach is safe?
Thanks!
Assemblies in Typhoon serve two purposes:
At build-time all of the information goes into TyphoonComponentFactory
, which is what is able to produce instances. On this class there are methods to retrieve components by type or by key - where key is a method name from one of your assembly classes.
(Side note: In Typhoon it is easy to declare multiple actors of the same type).
Then, to avoid the use of 'magic strings' assemblies (just the interface) can act as a facade in front of the TyphoonComponentFactory
to retrieve instances. What happens here is that Objective-C message forwarding is used.
This means that:
TyphoonComponentFactory
can build them. TyphoonComponentFactory
instance to one of your assembly interfaces and call methods on it. If there's a rule to build an instance matching the method name (and any args), then it will be returned, otherwise 'no component for key' is raised. This information is of a general nature - I suspect that if you know how things work behind the scenes, you'll know the kinds of things you can do, and what approaches are appropriate. If you'd like more specifics, please edit your question and I'll provide them.