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 06:07 Go to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
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 06:34 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5285
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 06:40 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

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 07:35 Go to previous messageGo to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
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 07:37 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

@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 08:05 Go to previous messageGo to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
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 08:07 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

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 08:26 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 347
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 08:38 Go to previous messageGo to next message
Christian Eugster is currently offline Christian Eugster
Messages: 134
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 13:35 Go to previous messageGo to next message
Lars Vogel is currently offline Lars Vogel
Messages: 1048
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 05:57 Go to previous message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

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 Aug 22 15:41:55 EDT 2014

Powered by FUDForum. Page generated in 0.01875 seconds