Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » At what Point to insert a singleton class into the model?
At what Point to insert a singleton class into the model? [message #987874] Wed, 28 November 2012 13:25 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
I have a Singleton class, which should do some work, every time when a new Object is inserted into the Context.

If it would be in the model - I could do something like that inside the Singleton:

@Inject
onChange(MyClass monitor){
 //do the work here
}


What would be the best way to attach the Singleton to model, in order to monitor MyClass changes inside the context?
Re: At what Point to insert a singleton class into the model? [message #987877 is a reply to message #987874] Wed, 28 November 2012 13:34 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Ideas that come to mind:
1) Add it to the Model as an AddOn
2) Create and add the instance to the application context manualy on @PostContextCreate in your life cycle handler.

You should probably use @Optional too, since there will probably not be a MyClass in the context on creation of your singleton.
Re: At what Point to insert a singleton class into the model? [message #987878 is a reply to message #987874] Wed, 28 November 2012 13:37 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
As far as I have understood, I would suggest to create your Singleton not as a Singleton, but as a POJO. Then annotate your class with @Creatable and @Singleton, and let the container do the "magic".

If you need to create your Singleton yourself with some initialization parameters or whatever, I guess a lifecycle hook method annotated with @PostContextCreate would be the best place to add it to the context.
Re: At what Point to insert a singleton class into the model? [message #987883 is a reply to message #987878] Wed, 28 November 2012 14:12 Go to previous message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 260
Registered: July 2012
Senior Member
Thnx Dirk, Christoph!
The @Creatable approach is what i need.

An other way could be using context.runAndTrack(new RunAndTrack()) to track object changes in context.
Previous Topic:How to create a handler by id?
Next Topic:XWT ValidationRule question
Goto Forum:
  


Current Time: Wed Apr 24 23:41:52 GMT 2024

Powered by FUDForum. Page generated in 0.02743 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top