|Place dependency in window context [message #1730034]
||Thu, 21 April 2016 06:20
| Colin Sharples
Registered: July 2009
Location: Wellington, New Zealand
I have a controller class that is shared around between several parts and handlers. I originally had this as a @Creatable @Singleton, so that it was available for any of the parts, but it was getting created after the handlers, so I had to inject it into the @Execute and @CanExecute methods, which was a bit messy.|
I changed to use an addon, and registered that addon to run before the command service, so that it was now available for the handlers as well as the parts. All good so far.
I then added another window to the application, which reuses some of the parts, but has a different set of handlers. This caused problems, because some of the controller functionality required the selection and part services, which are bound to the window context. The parts in the second window were not working correctly as the controller was really bound to the first window.
I fixed this by changing the add on to create two instances of the controller class, bound to different names. Each part and handler then uses @Named to retrieve the correct instance, so now it all works again.
However, this still seems like a lot of work. It would be a lot easier if there was a context scope annotation, so instead of just @Singleton you could specify that the @Creatable should be one per part, window or application.
In the absence of such an annotation, is there another way that I can bind the different controller instances into the window context, rather than having them both in the application context but under different names?
CTG Games Ltd
Wellington, New Zealand
Powered by FUDForum
. Page generated in 0.05241 seconds