Hi all,
I am learning wire in my weekend project. It's a great tool, I would say. However, I am facing a problem that I don't know how to solve. I hope you can give me some advises. Thanks a lot in advance.
In my application, I have a ViewContainer object which is responsible for loading views according to view name on the hash. The ViewContainer instance is a singleton created in the root wire context. To be able to load views, the ViewContainer need to create view instances. I want to create the view with its dependencies (property injection) using wire. I am trying 3 approaches:
1) Define all the views' specification in the root context and inject them into the ViewContainer
This is really inefficient because everything is loaded, instantiated as soon as the root context is resolved.
2) Define each view's specification in its own spec and inject to the ViewContainer in the root context using wire factory.
This is better since the view is not loaded until the view container needs it. Problem here is that I need so many spec files. Says, I have 300 views, then I need 300 spec which is not nice.
3) Programmatically load the view context into the root context
I keep all the views' spec in a single specification file, identified by view name. Once the view container needs to create a view, I only take that view's spec and feed to rootContext.wire(). My problem here is that I have to pass the rootContext all the way from the root application object to the view container which is not good. I also think that using the root context in the wired component is not recommended in IoC world.
Any help would be really appreciated.
Thanks