Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Eclipse4 DI reinject?
Eclipse4 DI reinject? [message #966885] Thu, 01 November 2012 10:07 Go to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi,

I have read, that the Eclipse4 DI framework does reinject a service if it has changed. Does it do this in a "silent way" or what opportunity has the "client" to react on this change?

E.g. I use a service to get instances from a database. If that service stops running, I want to remove the instances from the ui. How can I accomplish this?

Thanks!
Re: Eclipse4 DI reinject? [message #966914 is a reply to message #966885] Thu, 01 November 2012 10:34 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
If you use method injection your method gets called and you can react on
that.

Tom

Am 01.11.12 11:07, schrieb Christian Eugster:
> Hi,
> I have read, that the Eclipse4 DI framework does reinject a service if
> it has changed. Does it do this in a "silent way" or what opportunity
> has the "client" to react on this change?
> E.g. I use a service to get instances from a database. If that service
> stops running, I want to remove the instances from the ui. How can I
> accomplish this?
>
> Thanks!
Re: Eclipse4 DI reinject? [message #966919 is a reply to message #966885] Thu, 01 November 2012 10:40 Go to previous messageGo to next message
Eclipse UserFriend
suppose you have
@Inject
public void doStuff(IMyService service){blablabla}

There are two alternatives:
1. you get IMyService through a context function
2. you get it directly from an IEclipseContext

1: If any value in the context which is used to compute the IMyService runtime class changes then the IMyService is reinjected and the method is re-called with the new value

2: If you change it through something like
eclipseContext.set(IMyService.class, myNewServiceObject)

the method is also re-called with the new value.
Re: Eclipse4 DI reinject? [message #966971 is a reply to message #966919] Thu, 01 November 2012 11:35 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi!

That's cool: and when I add @Optional the method is called when the service stops too!

Thank you both!
Re: Eclipse4 DI reinject? [message #966976 is a reply to message #966971] Thu, 01 November 2012 11:37 Go to previous messageGo to next message
Eclipse UserFriend
@Optional prevents it from being called when it becomes null.
Re: Eclipse4 DI reinject? [message #967002 is a reply to message #966976] Thu, 01 November 2012 12:05 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
So do I misunderstand something? I thought that @Optional does not prevent the method call, but does not throw an exception. When I want to be noticed about a service stops, how do I implement this then?
Re: Eclipse4 DI reinject? [message #967003 is a reply to message #967002] Thu, 01 November 2012 12:07 Go to previous messageGo to next message
Eclipse UserFriend
It depends what you mean by "service stops" do you have a mechanism to null the service in the context when something happens? The framework can not "automatically" check and act when a service "stops" as it is a bit ambiguous what you call stop.
Re: Eclipse4 DI reinject? [message #967024 is a reply to message #966976] Thu, 01 November 2012 12:26 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
@Sopot: I think you've got a criss-cross in your post Wink : @Optional allows (not prevents) the value to be injected with null
Re: Eclipse4 DI reinject? [message #967036 is a reply to message #967003] Thu, 01 November 2012 12:38 Go to previous messageGo to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
I have an OSGi Service that provides DAOs. When dependencies are no longer fulfilled, the service is deactivated and so not anymore reachable.
Re: Eclipse4 DI reinject? [message #967332 is a reply to message #967036] Thu, 01 November 2012 17:35 Go to previous messageGo to next message
Lars Vogel is currently offline Lars VogelFriend
Messages: 1098
Registered: July 2009
Senior Member

Of course if the OSGi services is stopped than the field or method injection will be performed again if you use @Optional. Have a look at the Javadoc of @Optional it depends where you use it.
Re: Eclipse4 DI reinject? [message #968235 is a reply to message #967024] Fri, 02 November 2012 09:57 Go to previous message
Eclipse UserFriend
Christoph Keimel wrote on Thu, 01 November 2012 13:26
@Sopot: I think you've got a criss-cross in your post Wink : @Optional allows (not prevents) the value to be injected with null


true.
Previous Topic:Integrate Eclipse Application with VC++ application
Next Topic:Tooltip black background with no text
Goto Forum:
  


Current Time: Fri Mar 29 05:25:16 GMT 2024

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

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

Back to the top